Inconsistent results when using fragments

I am finding that the order of data in the query really matters.

//query
const query = graphql`
    query EntryQuery($id: Float) {
      queryEntry(filter: { id: { eq: $id } }) {
        ...EntryBanner_entry
        images {
          source
        }
      }
    }
    ${EntryBannerFragment}
  `;

const fragment = graphql`
  fragment EntryBanner_entry on Entry {
    title
    images {
      source
      type
    }
  }
`;

This will output the correct object:

{
  title: string
  images: { source: string, type: string }[]
}

However if I change the order of the data and fragment:

const query = graphql`
    query EntryQuery($id: Float) {
      queryEntry(filter: { id: { eq: $id } }) {
        images {
          source
        }
        ...EntryBanner_entry
      }
    }
    ${EntryBannerFragment}
  `;

Then the object is:

{
  title: string
  images: { source: string }[]
}

Why is this the case?

Can you make sure that it is the same in general GraphQL Specs? For example, run an Apollo GraphQL server and test it. If it has the same behavior, it is part of GraphQL Spec and you may found why in their docs. If no, we can consider it as a Bug in Dgraph.

Cheers.

I have tested this using a simple Apollo and Hasura Server. The placement of the fragment didn’t matter, it always respected the data requested so this is a bug in Dgraph.

Your query and the fragment are both querying for images { ... }. Is that what you’re expecting? The behavior you’re reporting shows that the query is picking up the first occurrence. Dgraph needs to end up choosing one of the queries on the same field to return.

That is correct. When I tested on Apollo and Hasura both returned back the data I was asking for, no matter the order or how it was broken up in fragments. I’m assuming it is a bug if Dgraph is just choosing one occurrence and ignoring the rest since this isn’t how it is handled on Apollo or Hasura.

1 Like