dotansimha/graphql-code-generator
View on GitHub[typescript-document-nodes] Incorrect alias import
Open
#5460 opened on Jan 27, 2021
corehelp wantedpluginsstage/1-reproduction
Description
Describe the bug
When you set gqlImport to use a function that is not named gql, it will be aliased. However, the document node will use the original name.
import { graphql as gql } from 'gatsby';
export const Test = graphql`
query test {
foo {
id
}
}
`
It should either not use alias or make all the document node uses gql.
To Reproduce Steps to reproduce the behavior:
- My GraphQL schema:
type Foo {
id: ID!
}
type Query {
foo: Foo!
}
- My GraphQL operations:
query test {
foo {
id
}
}
- My
codegen.ymlconfig file:
schema: ./schema.gql
documents: ./src/**/*.gql
overwrite: true
generates:
./src/index.ts:
plugins:
- typescript
- typescript-operations
- typescript-document-nodes
config:
skipTypename: true
namingConvention:
transformUnderscore: true
gqlImport: gatsby#graphql
Expected behavior Generate TypeScript code without any errors.
Environment:
- OS: Windows 10
{
"@graphql-codegen/cli": "^1.20.1",
"@graphql-codegen/introspection": "^1.18.1",
"@graphql-codegen/typescript": "^1.20.2",
"@graphql-codegen/typescript-graphql-request": "^3.0.1",
"@graphql-codegen/typescript-operations": "^1.17.14",
"graphql-request": "^3.4.0",
"graphql": "^15.5.0"
}
- NodeJS: 15
Additional context
A temporary workaround is to export the function you want as gql from a local wrapper.
export { graphql as gql } from 'gatsby';
gqlImport: ./util#gql