Version 0.10.0 - Magic Imports
Magic #imports
This is a feature tries to replicate the apollographql/graphql-tag loader.js
feature, which enables including (or actually inlining) partials into a graphql query with magic comments.
Explained
The syntax is straightforward
#import path/to/included.fragment.graphql
The fragment files should be named liked this
<name>.fragment.graphql
There is a excludeFilter in graphqlCodegen
, which removes them from code generation so they are just used for inlining
and interface generation.
The resolving of paths works like this
- The path is resolved by checking all
sourceDirectories in graphqlCodegen
for the given path - No relative paths like
./foo.fragment.graphql
are supported - Imports are resolved recursively. This means you can
#import
fragments in a fragment.
Example
I have a file CharacterInfo.fragment.graphql
which contains only a single fragment
fragment CharacterInfo on Character {
name
}
And the actual graphql query file
query HeroFragmentQuery {
hero {
...CharacterInfo
}
human(id: "Lea") {
homePlanet
...CharacterInfo
}
}
#import fragments/CharacterInfo.fragment.graphql