Import specific GraphQL fragments?

Import specific GraphQL fragments?


0

I have a fragment in a file that contains a lot of other fragments.

file.gql

#import "./fragment.gql"

query Query {
   ...Fragment
}

fragment.gql

fragment Fragment {
   ...
}
...other fragments here

Doing this causes an error because of the unused fragments. Is it possible to import just that one fragment? Or do I seriously need to separate it into a different file to be able to use them?

You can imagine this becomes worse if I need to use X fragments of a file that contains X + 1 fragments.

1 Answer
1


0

I did not test this, but referring to the change log you should be able to import named fragments like this:

#import { myFragment1, myFragment2 } from './fragments.graphql'

(From GitHub https://github.com/apollographql/graphql-tag/pull/257)



Leave a Reply

Your email address will not be published. Required fields are marked *