Duplicate fragments errors

I am building an app using Dgraph Cloud and found unexpected behaviour when using fragments. I am not able to use duplicate fragments for a query.

For example I have three different types of banners, and they each use a description. So I have the three types of banners as fragments, and each including a description fragment.

const fragment = graphql`
  fragment EntryBanner_entry on Entry {
    ...EntryBannerWithPoster_entry
    ...EntryBannerWithBanner_entry
    ...EntryBannerWithText_entry
  }
  ${EntryBannerWithBannerFragment}
  ${EntryBannerWithPosterFragment}
  ${EntryBannerWithTextFragment}
`;

//here is an example of EntryBannerWithTextFragment (note each banner fragment has the description fragment

const fragment = graphql`
  fragment EntryBannerWithText_entry on Entry {
    title
    releaseYear
    movieLength
    ...EntryDescription_entry
  }
  ${EntryDescriptionFragment}
`;

However, since multiple fragments are being joined in EntryBanner_entry, it causes this error:

There can be only one fragment named "EntryDescription_entry".: {"response":{"errors":[{"message":"There can be only one fragment named \"EntryDescription_entry\".",...}

Having fragments attached to re-usable components is considered a good practice so I am unsure why the query response is erroring.

After some research it looks like this is due to a bug in the package @graphql-codegen. Has anyone else experienced this?

HI! I’ve just came across this and I have the same problem! It seems like that Dgraph is not compliant with Field Collection in the GraphQL specs. Unfortunately, I did not get a reply either from the community…

Here’s my thread

Did you find a solution? It is quite important, especially if you use Relay…

I don’t yet, I am working with the team at @graphql-codegen to see if I can remove duplicate fragments. It would be great if Dgraph is able to handle this.

1 Like