Created
June 21, 2020 09:45
-
-
Save hyochan/907ea3a08dc220728ba9cf6d4991d74a to your computer and use it in GitHub Desktop.
relay/fetch.ts
This file contains hidden or 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
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