Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (87 sloc) 2.3 KB
id title
GraphQL
GraphQL

GraphQL

Extends Helper

GraphQL helper allows to send additional requests to a GraphQl endpoint during acceptance tests. Axios library is used to perform requests.

Configuration

  • endpoint: GraphQL base URL
  • timeout: timeout for requests in milliseconds. 10000ms by default
  • defaultHeaders: a list of default headers
  • onRequest: a async function which can update request object.

Example

GraphQL: {
   endpoint: 'http://site.com/graphql/',
   onRequest: (request) => {
     request.headers.auth = '123';
   }
}

Access From Helpers

Send GraphQL requests by accessing _executeQuery method:

this.helpers['GraphQL']._executeQuery({
   url,
   data,
});

Methods

Parameters

  • config

_executeQuery

Executes query via axios call

Parameters

_prepareGraphQLRequest

Prepares request for axios call

Parameters

sendMutation

Send query to GraphQL endpoint over http

I.sendMutation(`
      mutation createUser($user: UserInput!) {
         createUser(user: $user) {
           id
           name
           email
         }
       }
   `,
  { user: {
      name: 'John Doe',
      email: 'john@xmail.com'
    }
  },
});

Parameters

  • mutation String
  • variables object that may go along with the mutation
  • options object are additional query options
  • headers object

sendQuery

Send query to GraphQL endpoint over http. Returns a response as a promise.

const response = await I.sendQuery('{ users { name email }}');
// with variables
const response = await I.sendQuery(
 'query getUser($id: ID) { user(id: $id) { name email }}',
 { id: 1 },
)
const user = response.data.data;

Parameters

  • query String
  • variables object that may go along with the query
  • options object are additional query options
  • headers object
You can’t perform that action at this time.