Skip to content

Instantly share code, notes, and snippets.

@hyochan
Created June 21, 2020 09:45
Show Gist options
  • Save hyochan/907ea3a08dc220728ba9cf6d4991d74a to your computer and use it in GitHub Desktop.
Save hyochan/907ea3a08dc220728ba9cf6d4991d74a to your computer and use it in GitHub Desktop.
relay/fetch.ts
import { CacheConfig, GraphQLResponse, RequestParameters, Variables } from 'relay-runtime';
const FETCH_URL = 'https://hackatalk.azurewebsites.net/graphql';
export type FetchArgProps = {
request: RequestParameters;
variables: Variables;
cacheConfig: CacheConfig;
token?: string | null;
};
async function fetchGraphQL(args: FetchArgProps): Promise<GraphQLResponse> {
const { request, variables, cacheConfig, token } = args;
const fetchConfig = {
method: 'POST',
headers: {
Authorization: token || '',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: request.text,
variables,
}),
};
return fetch(FETCH_URL, fetchConfig).then((response) => response.json());
}
export default fetchGraphQL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment