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

noGraphQLTag and near-operation-file config does not work with Fragment #2080

Closed
eddeee888 opened this issue Jun 29, 2019 · 4 comments
Closed
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@eddeee888
Copy link
Collaborator

eddeee888 commented Jun 29, 2019

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
@dotansimha
Copy link
Owner

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: #2106

@eddeee888 can you please test it? (alpha is available as 1.3.1-alpha-70a528d8.62)

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Jul 4, 2019
@eddeee888
Copy link
Collaborator Author

Will do this soon! Cheers!

@eddeee888
Copy link
Collaborator Author

Looking good @dotansimha

https://codesandbox.io/s/use-before-declare-unused-imports-kc7ov

@dotansimha
Copy link
Owner

Fixed in 1.4.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

2 participants