Skip to content
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

Breaks Apollo query deduplication #106

Open
martdavidson opened this issue Feb 12, 2020 · 2 comments
Open

Breaks Apollo query deduplication #106

martdavidson opened this issue Feb 12, 2020 · 2 comments

Comments

@martdavidson
Copy link

Issue
Using either loader or gql from this package breaks apollo-client's query deduplication.

Steps to Recreate
In two different components, fire the exact same query by either importing the same .graphql file with loader, or defining the same query with gql from this package. Render both components together, and you will see two network requests fire.

Expectation
If you do the same as the above but with gql from the graphql-tag package, Apollo recognizes that the two queries are the same, and only fires one network request. Could be related to apollographql/apollo-client#4930

Queries are deduplicated only according to the object reference of the DocumentNode.

I imagine this package is returning a different DocumentNode every time the query is imported / defined rather than building up a cache of already-compiled queries and check against that.

Is caching something that's in scope for this package?

@martdavidson
Copy link
Author

martdavidson commented Mar 17, 2020

For anyone else that comes by, my solution here was to configure Rescripts and use graphql-tag instead of this package.

You'll also require jest-transform-graphql if you're running tests against code that imports graphql files. This issue helped me correctly configure it for Jest.

Once you've done the above, you can simply import query from 'somewhere.graphql', and because graphql-tag caches correctly, Apollo Client's deduplication works as expected, and only one of the identical queries fires at a time.

@mschipperheyn
Copy link

When you have the same fragment multiple times in a query through nesting, it throws an error:

[GraphQL error]: Message: There can be only one fragment named "wallCommentFragment"., Location: [object Object],[object Object], Path: undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants