dotansimha / dotansimha/graphql-code-generator

[typescript-document-nodes] Incorrect alias import

Open
#5,460 0 comments 1 reaction 0 assignees View on GitHub
core help wanted plugins stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

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.

```typescript
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:

1. My GraphQL schema:

```graphql
type Foo {
id: ID!
}

type Query {
foo: Foo!
}
```

2. My GraphQL operations:

```graphql
query test {
foo {
id
}
}
```

3. My `codegen.yml` config file:

```yml
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
```json
{
"@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.

```typescript
export { graphql as gql } from 'gatsby';
```

```yaml
gqlImport: ./util#gql
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.