graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

[typescript-graphql-request] Importing not exported type

Open joshuaavalon opened this issue 5 years ago • 3 comments

Describe the bug typescript-graphql-request generates the following import

import { HeadersInit } from 'graphql-request/dist/types.dom';

HeadersInit is not exported from graphql-request

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-graphql-request
    config:
      skipTypename: true
      namingConvention:
        transformUnderscore: true

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

It should be

import { RequestInit } from 'graphql-request/dist/types.dom';

The header type should be RequestInit['headers']. That is how the graphql-request defines.

https://github.com/prisma-labs/graphql-request/blob/a8d99f5cdbe57786ecb8d99c88175599608d2fc6/src/index.ts#L47

joshuaavalon avatar Jan 27 '21 02:01 joshuaavalon

Workaround:

downgrade to "@graphql-codegen/typescript-graphql-request": "^3.0.0"

cafenroy avatar Jan 27 '21 21:01 cafenroy

downgrade to "@graphql-codegen/typescript-graphql-request": "3.0.0" without the ^ to avoid automatically patching to 3.0.1

ab316 avatar Jan 29 '21 14:01 ab316

Available in the latest release! Thanks!

ardatan avatar Feb 10 '21 15:02 ardatan