-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
customFetch configuration option doesn't appear to work with Next.js 15 #10213
Comments
Hello @linucks, If you are already using import type { CodegenConfig } from "@graphql-codegen/cli";
import myFetch from './myFetch'
const config: CodegenConfig = {
schema: "https://swapi-graphql.netlify.app/.netlify/functions/index",
documents: ["src/**/*.tsx"],
customFetch: myFetch as any, // Note: CodegenConfig's type doesn't have a function as a possible type, so `as any` is required. This can be fixed soon.
generates: {
"./src/gql/": {
preset: "client",
},
},
};
export default config; |
Thanks @eddeee888 - that's really helpful. In order to get it to work properly, I needed to add the following to run the command to make sure that tsconfig paths were resolved and the .env file was found (as I needed that to instantiate urql, which I use to set up the GraphQL client to log into the server and get the token): |
I see, thank you for sharing your approach! 🙌
Are these tokens long-lived? If yes, maybe you could fetch it once into a local, git-ignored |
No, they're short-lived (~5 minutes) JWT tokens from Wordpress so need to be refreshed. It works fine using the above approach, but thank you for the suggestion. |
Which packages are impacted by your issue?
@graphql-codegen/cli
Describe the bug
I'm following the documentation to use a custom fetch function, as I need to add authentication for accessing my GraphQL endpoint. I'm using the following codegen.ts file:
and have a file called
myFetch.ts
in the same directory as thecodegen.ts
file that contains:Whenever I try and run the command:
npx graphql-codegen --config codegen.ts
I get the error:
This happens regardless of where I put the myFetch.ts file or how I organise the imports.
Your Example Website or App
https://github.com/linucks/gqlcodegen-customfetch
Steps to Reproduce the Bug or Issue
npx graphql-codegen --config codegen.ts
Expected behavior
I expected the myFetch.ts file to be found and the function imported and used or all fetches by graphql-codgen.
Screenshots or Videos
No response
Platform
@graphql-codegen/*
version(s): 5.0.3Codegen Config File
import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
schema: "https://swapi-graphql.netlify.app/.netlify/functions/index",
documents: ["src/**/*.tsx"],
customFetch: "myFetch",
generates: {
"./src/gql/": {
preset: "client",
},
},
};
export default config;
Additional context
No response
The text was updated successfully, but these errors were encountered: