Replies: 1 comment
-
I don't know why it's not exposing the fetcher. @zecka did i make any wrong here?codegen.tsimport { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: `apps/api/src/**/*.gql`,
documents: 'libs/graphql/**/*.gql',
generates: {
'libs/graphql/src/graphql/index.ts': {
plugins: [
'typescript',
'typescript-operations',
'typescript-react-query',
],
config: {
fetcher: {
func: 'ui#useFetcher',
isReactHook: true,
},
pureMagicComment: true,
noHOC: true,
noComponents: true,
noNamespaces: true,
withHooks: true,
withSubscriptionHooks: true,
exposeQueryKeys: true, // We use it as the key for the react query without having to manually give a string.
exposeMutationKeys: true, // We use it as the key for the react query without having to manually give a string.
exposeFetcher: true, // exposes a fetch to use for SSR,
},
hooks: {
afterOneFileWrite: ['prettier --write'],
},
},
},
};
export default config; libs/ui/hooks/useFetcher.tsimport { headers } from 'next/headers';
export const useFetcher = <TData, TVariables>(
query: string,
options?: RequestInit['headers']
): ((variables?: TVariables) => Promise<TData>) => {
const headersInstance = headers();
return async (variables?: TVariables) => {
const res = await fetch(process.env.NX_API_URL + '/graphql', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
cookie: headersInstance.get('cookie') || '',
...options,
},
body: JSON.stringify({
query,
variables,
}),
});
const json = await res.json();
if (json.errors) {
const { message } = json.errors[0] || {};
throw new Error(message || 'Error…');
}
return json.data;
};
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm using graphql-code-generator on project with Next 13.
I'm using app router and I want to take leverage of new fetch extended api
So I update my previous custom fetcher to allow includes next object on option parameter (NextFetchRequestConfig)
But after this change the generated code seems not take into account the update options type.
Generated code still look like that
instead of
So, how to pass the new NextFetchRequestConfig object in customFetcher parameter ?
Bellow my config and fetcher code
codegen.ts
src/lib/fetchConfig.ts
Beta Was this translation helpful? Give feedback.
All reactions