feat: remove gated key for graphql query (#5447)

remove gated key for graphql query

Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
This commit is contained in:
Charles Bachmeier 2022-11-29 13:24:15 -08:00 committed by GitHub
parent 1195be5747
commit 0b18bf0813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,34 +7,15 @@ if (!GRAPHQL_URL) {
throw new Error('AWS URL MISSING FROM ENVIRONMENT') throw new Error('AWS URL MISSING FROM ENVIRONMENT')
} }
const baseHeaders = { const headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }
const nftHeaders = {
'Content-Type': 'application/json',
'x-api-key': process.env.REACT_APP_NFT_AWS_X_API_KEY ?? '',
}
// The issue below prevented using a custom var in metadata to gate which queries are for the nft endpoint vs base endpoint
// This is a temporary solution before the two endpoints merge
// https://github.com/relay-tools/relay-hooks/issues/215
const NFT_QUERIES = [
'AssetQuery',
'AssetPaginationQuery',
'CollectionQuery',
'DetailsQuery',
'NftBalanceQuery',
'NftBalancePaginationQuery',
]
const fetchQuery = (params: RequestParameters, variables: Variables): Promise<GraphQLResponse> => { const fetchQuery = (params: RequestParameters, variables: Variables): Promise<GraphQLResponse> => {
const isNFT = NFT_QUERIES.includes(params.name)
const body = JSON.stringify({ const body = JSON.stringify({
query: params.text, // GraphQL text from input query: params.text, // GraphQL text from input
variables, variables,
}) })
// TODO: When gating is removed from gql endpoint, we can remove the isNFT check and just use base headers
const headers = isNFT ? nftHeaders : baseHeaders
return fetch(GRAPHQL_URL, { method: 'POST', body, headers }) return fetch(GRAPHQL_URL, { method: 'POST', body, headers })
.then((res) => res.json()) .then((res) => res.json())