🚨 Announcing Vendure v2 Beta

SimpleGraphQLClient

SimpleGraphQLClient

A minimalistic GraphQL client for populating and querying test data.

Signature

class SimpleGraphQLClient {
  constructor(vendureConfig: Required<VendureConfig>, apiUrl: string = '')
  setAuthToken(token: string) => ;
  setChannelToken(token: string | null) => ;
  getAuthToken() => string;
  async query(query: DocumentNode, variables?: V, queryParams?: QueryParams) => Promise<T>;
  async fetch(url: string, options: RequestInit = {}) => Promise<Response>;
  async queryStatus(query: DocumentNode, variables?: V) => Promise<number>;
  async asUserWithCredentials(username: string, password: string) => ;
  async asSuperAdmin() => ;
  async asAnonymousUser() => ;
  async fileUploadMutation(options: {
        mutation: DocumentNode;
        filePaths: string[];
        mapVariables: (filePaths: string[]) => any;
    }) => Promise<any>;
}

Members

constructor

method
type:
(vendureConfig: Required<VendureConfig>, apiUrl: string = '') => SimpleGraphQLClient

setAuthToken

method
type:
(token: string) =>
Sets the authToken to be used in each GraphQL request.

setChannelToken

method
type:
(token: string | null) =>
Sets the authToken to be used in each GraphQL request.

getAuthToken

method
type:
() => string
Returns the authToken currently being used.

query

async method
type:
(query: DocumentNode, variables?: V, queryParams?: QueryParams) => Promise<T>
Performs both query and mutation operations.

fetch

async method
type:
(url: string, options: RequestInit = {}) => Promise<Response>
Performs a raw HTTP request to the given URL, but also includes the authToken & channelToken headers if they have been set. Useful for testing non-GraphQL endpoints, e.g. for plugins which make use of REST controllers.

queryStatus

async method
type:
(query: DocumentNode, variables?: V) => Promise<number>
Performs a query or mutation and returns the resulting status code.

asUserWithCredentials

async method
type:
(username: string, password: string) =>
Attemps to log in with the specified credentials.

asSuperAdmin

async method
type:
() =>
Logs in as the SuperAdmin user.

asAnonymousUser

async method
type:
() =>
Logs out so that the client is then treated as an anonymous user.

fileUploadMutation

async method
type:
(options: { mutation: DocumentNode; filePaths: string[]; mapVariables: (filePaths: string[]) => any; }) => Promise<any>