Skip to main content

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;
query(query: DocumentNode | TypedDocumentNode<T, V>, variables?: V, queryParams?: QueryParams) => Promise<T>;
fetch(url: string, options: RequestInit = {}) => Promise<Response>;
queryStatus(query: DocumentNode, variables?: V) => Promise<number>;
asUserWithCredentials(username: string, password: string) => ;
asSuperAdmin() => ;
asAnonymousUser() => ;
fileUploadMutation(options: {
mutation: DocumentNode;
filePaths: string[];
mapVariables: (filePaths: string[]) => any;
}) => Promise<any>;
}

constructor

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

setAuthToken

method
(token: string) =>

Sets the authToken to be used in each GraphQL request.

setChannelToken

method
(token: string | null) =>

Sets the authToken to be used in each GraphQL request.

getAuthToken

method
() => string

Returns the authToken currently being used.

query

method
(query: DocumentNode | TypedDocumentNode<T, V>, variables?: V, queryParams?: QueryParams) => Promise<T>

Performs both query and mutation operations.

fetch

method
(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

method
(query: DocumentNode, variables?: V) => Promise<number>

Performs a query or mutation and returns the resulting status code.

asUserWithCredentials

method
(username: string, password: string) =>

Attempts to log in with the specified credentials.

asSuperAdmin

method
() =>

Logs in as the SuperAdmin user.

asAnonymousUser

method
() =>

Logs out so that the client is then treated as an anonymous user.

fileUploadMutation

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

Perform a file upload mutation.

Upload spec: https://github.com/jaydenseric/graphql-multipart-request-spec Discussion of issue: https://github.com/jaydenseric/apollo-upload-client/issues/32