Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get rid of the 'data' ,'nodes', ... fields?

I have the following GraphQL query:

{
  allForums {
    nodes {
      name,
      topics: topicsByForumId(orderBy: [TITLE_ASC]) {
        nodes {
          title
        }
      }
    }
  }
}

This returns something as following:

{
  "data": {
    "allForums": {
      "nodes": [
        {
          "name": "1",
          "topics": {
            "nodes": [
              {
                "title": "a"
              },
              {
                "title": "b"
              }
            ]
          }
        }
      ]
    }
  }
}

I would like to get the result below:

[
    {
        "name": "1",
        "topics": [
            {
                "title": "a"
            },
            {
                "title", "b"
            }
        ]
    }
]

Is it possible to get rid of the data, nodes, ... fields? Is that something that can be done within GraphQL, or should I do that in my service implementation?

I am using PostGraphile v4.2.0 as a GraphQL implementation, on top of PostgreSQL v11.

like image 544
Opl0 Avatar asked Dec 27 '18 10:12

Opl0


1 Answers

As indicated in the docs, you can expose a simpler interface for connections, or eliminate the default Relay-based connection interface altogether:

If you prefer a simpler list interface over GraphQL connections then you can enable that either along-side our connections (both) or exclusively (only) using our --simple-collections [omit|both|only] option.

like image 134
Daniel Rearden Avatar answered Oct 17 '22 01:10

Daniel Rearden