Describe the bug
I'm using both noGraphQLTag and near-operation-file to generate files with fragment. I keep getting the following error:
✖ Generate
→ Syntax Error: Unexpected $
Found 1 error
✖ GraphQL request
Syntax Error: Unexpected $
GraphQL request (7:5)
6: }
7: ${GetProjectFragFragmentDoc}
If I don't use fragment, it works!
To Reproduce
Steps to reproduce the behavior:
type Project {
id: ID!
status: Status!
}
enum Status {
INITIAL
PENDING
COMPLETED
}
type Query {
project: Project!
}
schema {
query: Query
}
fragment GetProjectFrag on Project {
id
status
}
query GetProject {
project {
...GetProjectFrag
}
}
codegen.yml config file:overwrite: true
schema: 'schema.graphql'
documents: './src/**/*.graphql'
generates:
src/gql/__generated__/types.ts:
plugins: 'typescript'
src/:
preset: near-operation-file
presetConfig:
extension: .generated.tsx
baseTypesPath: gql/__generated__/types.ts
plugins:
- add: /* eslint-disable */
- typescript-operations
- typescript-react-apollo
config:
noGraphQLTag: true
Expected behavior
Fragment be turned into DocumentNode correctly
Environment:
You can check the following sandbox:
https://codesandbox.io/s/use-before-declare-unused-imports-kc7ov
Run the following in the terminal:
$ yarn codegen
Tested it now, and it seems like it's not related only to near-operation-file.
The combination of fragments and noGraphQlTag doesn't work, because we need to compile the fragment and build a single DocumentNode (with both OperationDefinition and FragmentDefinitions).
I tried to fix it in: https://github.com/dotansimha/graphql-code-generator/pull/2106
@eddeee888 can you please test it? (alpha is available as 1.3.1-alpha-70a528d8.62)
Will do this soon! Cheers!
Looking good @dotansimha
https://codesandbox.io/s/use-before-declare-unused-imports-kc7ov
Fixed in 1.4.0 🎉