-
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.
Merge pull request #3 from cofacts/nextjs-fetch
Support Nextjs fetch options in graphql-request
- Loading branch information
Showing
4 changed files
with
38 additions
and
13 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,21 @@ | ||
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 | ||
* @see https://github.com/dotansimha/graphql-typed-document-node?tab=readme-ov-file#how-can-i-support-this-in-my-library | ||
*/ | ||
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