dotansimha / graphql-code-generator-community

MIT License
115 stars 147 forks source link

@graphql-codegen/typescript-graphql-request uses wrong import for gql in ESM #323

Open ldrick opened 1 year ago

ldrick commented 1 year ago

Which packages are impacted by your issue?

@graphql-codegen/typescript-graphql-request

Describe the bug

If you try to generate a ESM compatible sdk with @graphql-codegen/typescript-graphql-request it imports gql namespace, instead of {gql} function

Your Example Website or App

https://the-guild.dev/graphql/codegen

Steps to Reproduce the Bug or Issue

  1. Go to https://the-guild.dev/graphql/codegen
  2. Provide this codegen.yml:
    generates:
    sdk.ts:
    plugins:
      - typescript
      - typescript-graphql-request
    config:
      emitLegacyCommonJSImports: false
  3. See the
    import gql from 'graphql-tag';

Expected behavior

should output

import {gql} from 'graphql-tag';

Screenshots or Videos

No response

Platform

Codegen Config File

No response

Additional context

Workaround:

// gql-fix.ts
import { gql } from "graphql-tag";

export { gql };

and use it like:

generates:
  sdk.ts:
    plugins:
      - typescript
      - typescript-graphql-request
    config:
      emitLegacyCommonJSImports: false
      gqlImport: ./gql-fix.js#gql,
simenandre commented 1 year ago

Another workaround is:

generates:
  sdk.ts:
    plugins:
      - typescript
      - typescript-graphql-request
    config:
      emitLegacyCommonJSImports: false
      gqlImport: graphql-tag#gql,