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

[graphql-tag/loader] Allow importing named fragments in .graphql #251

Closed
LevanArabuli opened this issue Apr 22, 2019 · 5 comments
Closed

Comments

@LevanArabuli
Copy link

LevanArabuli commented Apr 22, 2019

Currently importing fragments in .graphql files imports everything, would be nice to have named imports. The problem is that Apollo Client will send all fragments with request, instead of filtering only what's actually used, eventually it results in server error Fragment "X" is never used.

// fragments.graphql
fragment info1 on Entity1 {
	id
	name
}

fragment info2 on Entity2 {
	title
	description
}
// someQuery.graphql

#import { info2 } from './fragments.graphql'
.
.
.

As a workaround we can split fragments into very granular files for sure, but it would be nice to have this feature.

@dobesv
Copy link
Contributor

dobesv commented May 2, 2019

Dupe of #102 ?

@toddpadwick
Copy link

Can anyone tell me how I get this to work? I can't find specific documentation on it.

I have queries in GQL files in which I have fragments which are also used in other gql query files.

getEntry.gql

I need to import a specific fragment from my fragments.gql file but I get a syntax error due to the import statement along with unknown fragment.

how do I use es6 js import statement inside the gql files?

@dobesv
Copy link
Contributor

dobesv commented Jun 10, 2021

how do I use es6 js import statement inside the gql files?

You can't use es6 import in gql files. Some GraphQL setups do allow another kind of import, though.

e.g. https://www.graphql-tools.com/docs/schema-loading/

@dobesv
Copy link
Contributor

dobesv commented Jun 10, 2021

I guess the fix in #102 was not actually a fix for this issue, because this issue is talking about imports written into the .graphql files where as #102 is talking about importing graphql files from a JavaScript file.

@clieee
Copy link

clieee commented Jun 29, 2021

So importing specific fragments from a .gql file that contains multiple fragments will simply not work as it is right now? And will result in error message?:
Error: Fragment "[NAME OF FRAGMENT]" is never used.

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

4 participants