A simple GraphQL call handler.

How to: https://stepzen.com/blog/consume-graphql-in-javascript

Helpfull tool: https://graphiql-online.com/

Properties

apiKey: string

An API key which will be added to the header of the request in the form of "Authorization": "Token apiKey"

cache: boolean

Caches the requests and returns the results of previously made requests instead of making a new request if the "endpoint", "apiKey", "query" and "variables" are exact matches.

Only successful requests which return content are cached.

endpoint: string

The endpoint/url of the GraphQL API.

errorFalse: boolean

If set and an error occurs during the call, the returned result is "false". Otherwise the returned value is the error log.

errorLog: boolean

In case of an error, console.log extensive error log.

Printed query and variables con be used at https://graphiql-online.com/

Methods

  • Sends a GraphQL query to the endpoint and returns the result as data object.

    Parameters

    • query: string

      the query as string (compatible with graphqlbuilder.stringRequest(...))

    • Optional variables: {
          [key: string]: string | number | boolean | string[] | number[] | boolean[];
      }

      the variables used in the query as {key: value, ...} object (optional)

      • [key: string]: string | number | boolean | string[] | number[] | boolean[]
    • Optional log: boolean

      console.log the query and its variables

    Returns Promise<any>

Generated using TypeDoc