Graphql-code-generator: `noGraphQLTag` and `near-operation-file` config does not work with Fragment

Created on 29 Jun 2019  Â·  4Comments  Â·  Source: dotansimha/graphql-code-generator

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:

  1. My GraphQL schema:
type Project {
   id: ID!
   status: Status!
}

enum Status {
    INITIAL
    PENDING
    COMPLETED
}

type Query {
    project: Project!
}

schema {
    query: Query
}
  1. My GraphQL operations:
fragment GetProjectFrag on Project {
    id
    status
}

query GetProject {
    project {
        ...GetProjectFrag
    }
}
  1. My 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
bug plugins waiting-for-release

All 4 comments

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!

Fixed in 1.4.0 🎉

Was this page helpful?
0 / 5 - 0 ratings