Super simple GraphQL fetch client, with built in error handling.
npm add fetch-graphql
import fetchGraphQL from 'fetch-graphql'
const query = `
query ListUsers($filter: UserFilter) {
users(filter: $filter) {
id
firstName
lastName
}
}
`
const variables = {
filter: {
firstName: 'Safaiyeh'
}
}
const data = await fetchGraphQL(
'https://yourAPI.com/graphql',
query,
variables,
{ 'header1': 'headerValue1', ...headers }
)
console.log(data.users)
If the GraphQL response contains errors, the returned Promise
will reject with a fully populated error. If there was multiple errors, it rejects with an AggregateError
that contains all the errors.
Pass your API Key to x-api-key header
const headers = {
'x-api-key': '<AWS KEY HERE>'
}