Class: BaseGraphqlService

(abstract) core/base-service/base-graphql~BaseGraphqlService()

Services which query a GraphQL endpoint should extend BaseGraphqlService

Constructor

(abstract) new BaseGraphqlService()

Source:

Methods

_parseJson(buffer) → {object}

Parse data from JSON endpoint

Parameters:
Name Type Description
buffer string

JSON response from upstream API

Source:
Returns:

Parsed response

Type
object

(async) _requestGraphql(attrs) → {object}

Request data from an upstream GraphQL API, parse it and validate against a schema

Parameters:
Name Type Description
attrs object

Refer to individual attrs

Properties
Name Type Attributes Default Description
schema Joi

Joi schema to validate the response against

url string

URL to request

query object

Parsed GraphQL object representing the query clause of GraphQL POST body e.g. gql{ query { ... } }

variables object

Variables clause of GraphQL POST body

options object <optional>
{}

Options to pass to got. See documentation

httpErrorMessages object <optional>
{}

Key-value map of HTTP status codes and custom error messages e.g: { 404: 'package not found' }. This can be used to extend or override the default

systemErrors object <optional>
{}

Key-value map of got network exception codes and an object of params to pass when we construct an Inaccessible exception object e.g: { ECONNRESET: { prettyMessage: 'connection reset' } }. See got error codes for allowed keys and module:core/base-service/errors~RuntimeErrorProps for allowed values

logErrors Array.<number> <optional>
[429]

An array of http error codes that will be logged (to sentry, if configured).

transformJson function <optional>
data => data

Function which takes the raw json and transforms it before further processing. In case of multiple query in a single graphql call and few of them throw error, partial data might be used ignoring the error.

transformErrors function <optional>
defaultTransformErrors

Function which takes an errors object from a GraphQL response and returns an instance of ShieldsRuntimeError. The default is to return the first entry of the errors array as an InvalidResponse.

Source:
See:
Returns:

Parsed response

Type
object