question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested fragment results arent't merged into a query result

See original GitHub issue

When a fragment selects nested fields and the original query also selects fields on that type, the fields from the fragment are left out and only the ones from the query are in the result.

Intended outcome:

The results from the nested fields of the fragment should be merged into the complete result.

Actual outcome:

The nested fields are left out.

How to reproduce the issue:

Here’s a query that can be run in Githunts’ GraphiQL. Notice that login as well as avatar_url is available in the result.

When the same query is run with apollo-client, only avatar_url is available in the result.

Here’s a node script that shows the issue:

require('isomorphic-fetch');
const {default: ApolloClient, createNetworkInterface} = require('apollo-client');
const gql = require('graphql-tag').default;

const client = new ApolloClient({
  networkInterface: createNetworkInterface({uri: 'http://www.githunt.com/graphql'})
});

const query = gql`
fragment RepositoryData on Repository {
  owner {
    login
  }
}

{
  feed(type: NEW, limit: 5) {
    repository {
      ...RepositoryData
      name
      owner {
        avatar_url
      }
    }
  }
}
`;

const promise = client.query({query}).then(({data}) => {
  console.log(JSON.stringify(data));
}, e => {
  console.error(res);
});

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ksmthcommented, May 5, 2017

if you change

repository {
  ...RepositoryData
  name
  owner {
    avatar_url
  }
}

to read like this:

repository {
  name
  owner {
    avatar_url
  }
  ...RepositoryData
}

it works. This also works for as many fragments in any order, so it seems for now it’s best to always put them last.

1reaction
stubailocommented, Jun 5, 2017

Note that this issue is now fixed as of graphql-anywhere 3.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relay: How to merge instead of override queries in nested ...
The problem is, that both App and UserList have defined fragements and it seems that only the query of UserList is send. Fragment...
Read more >
Customizing the behavior of cached fields - Apollo GraphQL
You can use a merge function to intelligently combine nested objects that are not normalized in your cache, assuming those objects are nested...
Read more >
com.fulcrologic.fulcro.algorithms.merge - cljdoc
Calculates the query that can be used to pull (or merge) a component with an ident to/from a normalized app database. Requires a...
Read more >
Postgres: Sort query results | Hasura GraphQL Docs
Sort query results on Postgres in Hasura. ... The argument can be used to sort nested objects too. The sort order (ascending vs....
Read more >
Nested fragments not being retained in support library v4 rev ...
Nested fragments do get retained on configuration changes (as expected) when reverting back to rev 19.1.0. Relevant sample code attached to reproduce the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found