New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten single scalar field child results #268

Open
kbrandwijk opened this Issue Jun 22, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@kbrandwijk
Contributor

kbrandwijk commented Jun 22, 2017

This query:

query
{
  Post(id: "cj3j0ylcmz72w01282yhxbp9r"){
    id
    description
    postItems {
      title
    }
  }
}

Returns:

{
  "data": {
    "Post": {
      "id": "cj3j0ylcmz72w01282yhxbp9r",
      "description": "Another Cat",
      "postItems": [
        {
          "title": "FirstItem"
        },
        {
          "title": "SecondItem"
        }
      ]
    }
  }
}

It would be nice do be able to do:

query
{
  Post(id: "cj3j0ylcmz72w01282yhxbp9r"){
    id
    description
    postItems @flatten {
      title
    }
  }
}

That would give you:

{
  "data": {
    "Post": {
      "id": "cj3j0ylcmz72w01282yhxbp9r",
      "description": "Another Cat",
      "postItems": ["FirstItem", "SecondItem"]
    }
  }
}
@marktani

This comment has been minimized.

Show comment
Hide comment
@marktani

marktani Jun 22, 2017

Member

One complication with the way you've written it down is that fields/nodes are typed and your two queries return would require different types for postItems.

This feature request has also been discussed as a feature request for GraphQL. Maybe you can add your voice there as well?

Member

marktani commented Jun 22, 2017

One complication with the way you've written it down is that fields/nodes are typed and your two queries return would require different types for postItems.

This feature request has also been discussed as a feature request for GraphQL. Maybe you can add your voice there as well?

@kbrandwijk

This comment has been minimized.

Show comment
Hide comment
@kbrandwijk

kbrandwijk Jun 22, 2017

Contributor

Great, will do!

Contributor

kbrandwijk commented Jun 22, 2017

Great, will do!

@grahamegrieve

This comment has been minimized.

Show comment
Hide comment
@grahamegrieve

grahamegrieve Oct 26, 2017

It's extremely tricky, if you use this, to track whether the output of the children should or shouldn't be a list. The simple case is ok, but as you start adding conditions and aliases, it can become pretty difficult to keep track of things

grahamegrieve commented Oct 26, 2017

It's extremely tricky, if you use this, to track whether the output of the children should or shouldn't be a list. The simple case is ok, but as you start adding conditions and aliases, it can become pretty difficult to keep track of things

@grahamegrieve

This comment has been minimized.

Show comment
Hide comment
@grahamegrieve

grahamegrieve commented Oct 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment