Skip to content

Instantly share code, notes, and snippets.

@gusfune
Created November 21, 2022 18:22
Show Gist options
  • Save gusfune/a52e8cda24207ccb383f90ec5d47ad33 to your computer and use it in GitHub Desktop.
Save gusfune/a52e8cda24207ccb383f90ec5d47ad33 to your computer and use it in GitHub Desktop.
The world lightest GraphQL Client
interface GraphQLResponse {
data: unknown
}
const noqlFetcher = async <T>(
endpoint: string,
query: string,
variables?: object,
headers: object = {}
): Promise<T> => {
const req = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
...headers,
},
body: JSON.stringify({
query,
variables,
}),
redirect: "follow",
})
const responseJson = (await req.json()) as GraphQLResponse
return responseJson.data as T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment