Flattening a particular node?

Is there a way in GraphQL to “flatten” a particular node:

{
  graph(func: eq(msisdn,"operator")){

    Transfer  @filter(ge(at, "2017-06-30T11:00:00Z") and lt(at, "2017-06-30T12:00:00Z")) {

      xid
      amount
      from
      to
      at
      t
      type {
        xid
      }
    }
  }
}

produces:

"Transfer": [
          {
            "xid": "xxx",
            "amount": 11881700,
            "to": "yyy",
            "at": "2017-06-30T11:24:40Z",
            "type": [
              {
                "xid": "TRANSFER"
              }
            ]
          },

but it would be nice to have:

"Transfer": [
          {
            "xid": "xxx",
            "amount": 11881700,
            "to": "yyy",
            "at": "2017-06-30T11:24:40Z",
            "type":  "TRANSFER"
          },
1 Like

Checkout @normalize directive https://docs.dgraph.io/query-language/#normalize-directive.

Yes, I’ve already experimented with that. That flattens everything. I just want to flatten the “Type” node into the “Transfer” node.

I see, what you are looking for is normalize for subqueries such that it is only applied on the subgraph starting at type. We have an open issue for this https://github.com/dgraph-io/dgraph/issues/1755.

Yes, that is exactly what I want. I wonder how hard that would be to implement? This is open source after all!

Shouldn’t be very hard. Happy to accept a PR if you want to give it a try. Or you can leave a comment on the issue that you find it useful and we can try and prioritize it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.