dotansimha/graphql-code-generator

[typescript-document-nodes] Incorrect alias import

Open

#5 460 ouverte le 27 janv. 2021

Voir sur GitHub
 (0 commentaires) (1 réaction) (0 assignés)TypeScript (1 295 forks)batch import
corehelp wantedpluginsstage/1-reproduction

Métriques du dépôt

Stars
 (10 341 stars)
Métriques de merge PR
 (Merge moyen 22j 9h) (53 PRs mergées en 30 j)

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:

  1. My GraphQL schema:
type Foo {
  id: ID!
}

type Query {
  foo: Foo!
}
  1. My GraphQL operations:
query test {
  foo {
    id
  }
}
  1. My codegen.yml config 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

Guide contributeur