-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate nextjs fetch with graphql-client
- Allows us to set fetch option specific to Next.JS in graphql-client
- Loading branch information
Showing
4 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GraphQLClient } from 'graphql-request'; | ||
import { TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
export { graphql } from '@/typegen/gql'; | ||
|
||
/** | ||
* @param operation | ||
* @param variables - the variables for the operation | ||
* @param fetchOptions - the options for NextJS's fetch | ||
* @returns graphql-request's request result | ||
*/ | ||
export function gql<TData = any, TVariables = Record<string, any>>( | ||
operation: TypedDocumentNode<TData, TVariables>, | ||
variables?: TVariables, | ||
fetchOptions?: Parameters<typeof fetch>[1] | ||
) { | ||
const client = new GraphQLClient(process.env.COFACTS_API_URL ?? '', { | ||
fetch: (input, init) => fetch(input, { ...init, ...fetchOptions }), | ||
}); | ||
return client.request(operation, { ...variables }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters