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

Unneccessarily importing unused FragmentDoc if near-operation-file and noGraphQLTag are used #2168

Closed
eddeee888 opened this issue Jul 14, 2019 · 3 comments
Labels
plugins waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@eddeee888
Copy link
Collaborator

eddeee888 commented Jul 14, 2019

Describe the bug
FragmentDoc are imported without being used if used with near-operation-file preset and noGraphQLTag enabled. This happens when the fragment of a different file is being imported to be used in an operation.

Certain apps such as create-react-app enforces noUnusedLocals by default which causes TS compilation to fail.

To Reproduce

Go to this template and run yarn gg. GetProject.operation.generated.tsx is generated with 2 unused FragmentDoc: GetProject_IdFragmentDoc and GetProject_StatusFragmentDoc. These 2 fragments are separate files and are being used in the main GetProject query

https://codesandbox.io/s/gcg-14-experiments-c8l15

  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:
// GetProject_Id.graphql
fragment GetProject_Id on Project {
    id
}
// GetProject_Status.graphql
fragment GetProject_Status on Project {
    status
}
// GetProject.graphql
fragment GetProject_All on Project {
  id
  status
}

query GetProject {
    project {
      ...GetProject_Id
      ...GetProject_Status
      ...GetProject_All
    }
}
  1. My codegen.yml config file:
overwrite: true
schema: 'schema.graphql'
documents: './src/**/*.graphql'
generates:
  src/__generated__/types.ts:
    plugins:
      - typescript

  src/:
    preset: near-operation-file
    presetConfig:
      baseTypesPath: __generated__/types.ts
      extension: .generated.tsx
    plugins:
      - typescript-operations
      - typescript-react-apollo
    config:
      noGraphQLTag: true

Expected behavior
It should not include FragmentDoc if it's not used

Additional context
This is probably a side effect of #2106?

@dotansimha
Copy link
Owner

dotansimha commented Jul 31, 2019

Thanks @eddeee888 , and sorry for the delay. Fixed in: #2260 , you can try it with the alpha 1.4.1-alpha-6ee432d2.57.

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

@dotansimha Woo hoo! It's working as expected! Cheers mate!

@dotansimha
Copy link
Owner

Fixed in 1.5.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