question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graphql-request (5.0.0) fetcher generates invalid types

See original GitHub issue

Describe the bug

When using graphql-request as the fetcher the generated getcher code has typescript errors. This did not happin in Graphql-request (4.X.X).

The generated code with issues is as follows:

function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) {
  return async (): Promise<TData> => client.request<TData, TVariables>(query, variables, headers);
}

The tsc error that it gives is:

Error:(12, 79) TS2345: Argument of type '[TVariables | undefined, HeadersInit | undefined]' is not assignable to parameter of type 'TVariables extends Record<any, never> ? [variables?: TVariables | undefined, requestHeaders?: HeadersInit | undefined] : keyof RemoveIndex<TVariables> extends never ? [variables?: ...] : [variables: ...]'.

Your Example Website or App

local repo

Steps to Reproduce the Bug or Issue

Use the following codegen.ts

import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
	schema: {
		'https://SCHEMA-URL': {
			headers: {
			}
		}
	},
	documents: 'src/graphql/*.graphql',
	generates: {
		'./graphql.schema.json': {
			plugins: ['introspection']
		},
		'src/@types/graphql.types.ts': {
			plugins: ['typescript', 'typescript-operations', 'typescript-react-query', 'typescript-document-nodes'],
			config: {
				skipTypename: true,
				typesPrefix: 'Gql',
				fetcher: 'graphql-request',
				namePrefix: 'Dn'
			}
		}
	}
};

export default config;

You will get the error

Expected behavior

I would expect that the generated graphql.types.ts would not have typescript errors

Screenshots or Videos

No response

Platform

Codegen Config File

import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
	schema: {
		'https://SCHEMA-URL': {
			headers: {
			}
		}
	},
	documents: 'src/graphql/*.graphql',
	generates: {
		'./graphql.schema.json': {
			plugins: ['introspection']
		},
		'src/@types/graphql.types.ts': {
			plugins: ['typescript', 'typescript-operations', 'typescript-react-query', 'typescript-document-nodes'],
			config: {
				skipTypename: true,
				typesPrefix: 'Gql',
				fetcher: 'graphql-request',
				namePrefix: 'Dn'
			}
		}
	}
};

export default config;

Additional context

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Mario2804commented, Sep 27, 2022

This doesn’t seem right. @GimpMaster uses typescript-react-query as his plugin for code generation, while the fix is for typescript-graphql-request , which is a different one. From what I see and tried, doesn’t seem like it solved the initial issue with typescript-react-query. Or am I missing something?

2reactions
charlypolycommented, Sep 22, 2022

@GimpMaster @Zerebokep, I can confirm that the issue is solved when using graphql-request@next

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-query plugin with graphql-request fetcher generates ...
The latest version introduces an issue where, if an infinite query has no arguments, the react-query plugin generates invalid types. Your ...
Read more >
graphql-code-generator - Bountysource
The latest version introduces an issue where, if an infinite query has no arguments, the react-query plugin generates invalid types. Your Example Website...
Read more >
Invalid Syntax error while consuming graphql API
meanwhile I tried to implement 1 simple one without any input type Query{reportFormats : [ReportOutputFormat]} type ReportOutputFormat{ id : ...
Read more >
Testing - DGS Framework - Netflix Open Source
Create a test class with the following contents to test the ShowsDatafetcher from the getting started example. Java Kotlin. import com.
Read more >
graphql-request - npm
Minimal GraphQL client supporting Node and browsers for scripts or simple apps. Latest version: 5.1.0, last published: 9 days ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found