Skip to content

LinusU/fetch-graphql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch-graphql

Super simple GraphQL fetch client, with built in error handling.

Installing

npm add fetch-graphql

Usage

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)

Error handling

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.

AWS AppSync

Pass your API Key to x-api-key header

const headers = {
  'x-api-key': '<AWS KEY HERE>'
}

About

Super simple GraphQL fetch client

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%