Extends Helper
GraphQL helper allows to send additional requests to a GraphQl endpoint during acceptance tests. Axios (opens new window) library is used to perform requests.
GraphQL: { endpoint: 'http://site.com/graphql/', onRequest: (request) => { request.headers.auth = '123'; } }
Send GraphQL requests by accessing _executeQuery
method:
this.helpers['GraphQL']._executeQuery({ url, data, });
config
Executes query via axios call
request
object (opens new window)
Prepares request for axios call
operation
object (opens new window)
headers
object (opens new window)
Send query to GraphQL endpoint over http
I.sendMutation(` mutation createUser($user: UserInput!) { createUser(user: $user) { id name email } } `, { user: { name: 'John Doe', email: '[email protected]' } }, });
mutation
String (opens new window)
variables
object (opens new window) that may go along with the mutationoptions
object (opens new window) are additional query optionsheaders
object (opens new window)
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;
query
String (opens new window)
variables
object (opens new window) that may go along with the queryoptions
object (opens new window) are additional query optionsheaders
object (opens new window)
© 2015 DavertMik <[email protected]> (http://codegyre.com)
Licensed under the MIT License.
https://codecept.io/helpers/GraphQL/