Skip to main content

GraphQL script API reference

In operation scripts for GraphQL operations, despite the operation script API, the definitions below are available through the kreya.graphql namespace. For example:

import { expect } from 'chai';

kreya.graphql.onQueryCompleted(call => {
kreya.trace('The GraphQL query completed.');

kreya.test('Status code', () => expect(call.status.code).to.equal(200));
kreya.test('status is success', () => expect(call.status.isSuccess).to.be.true);

// You can check for GraphQL errors
if (call.response.content.errors) {
kreya.trace('GraphQL errors occurred');
}

kreya.test('First user name', () => expect(call.response.content.data.users[0].name).to.eq('John'));
});
info

Accessing call.response.content will throw an exception if the response size is greater than 10 MiB.

Accessing call.response.content will throw if the response content is not valid JSON.

Functions​

onMutationCompleted()​

function onMutationCompleted(callback: (arg: GraphQlScriptQueryCompletedContext) => void | Promise<void>): void;

Hook which is called when a GraphQL mutation completes.

Parameters​

ParameterTypeDescription
callback(arg: GraphQlScriptQueryCompletedContext) => void | Promise<void>The callback to be invoked.

Returns​

void


onQueryCompleted()​

function onQueryCompleted(callback: (arg: GraphQlScriptQueryCompletedContext) => void | Promise<void>): void;

Hook which is called when a GraphQL query completes.

Parameters​

ParameterTypeDescription
callback(arg: GraphQlScriptQueryCompletedContext) => void | Promise<void>The callback to be invoked.

Returns​

void


onSubscriptionCompleted()​

function onSubscriptionCompleted(callback: (arg: GraphQlScriptSubscriptionCompletedContext) => void | Promise<void>): void;

Hook which is called when a subscription is completed.

Parameters​

ParameterTypeDescription
callback(arg: GraphQlScriptSubscriptionCompletedContext) => void | Promise<void>-

Returns​

void


onSubscriptionEventReceived()​

function onSubscriptionEventReceived(callback: (arg: GraphQlScriptSubscriptionEventContext) => void | Promise<void>): void;

Hook which is called when a subscription event is received.

Parameters​

ParameterTypeDescription
callback(arg: GraphQlScriptSubscriptionEventContext) => void | Promise<void>-

Returns​

void

Type Aliases​

GraphQlScriptQueryCompletedContext​

type GraphQlScriptQueryCompletedContext = {
durationMillis: number;
headers: Record<string, string>;
response: GraphQlScriptQueryResponse;
status: HttpScriptStatus;
trailers: Record<string, string>;
};

Callback context of GraphQL completed call callback.

Properties​

durationMillis​
readonly durationMillis: number;

Duration of the call in milliseconds.

headers​
readonly headers: Record<string, string>;

The received headers.

response​
readonly response: GraphQlScriptQueryResponse;

The response.

status​
readonly status: HttpScriptStatus;

The status of the call.

trailers​
readonly trailers: Record<string, string>;

The received trailers.


GraphQlScriptQueryResponse​

type GraphQlScriptQueryResponse = {
content: any;
rawContentBytes: Uint8Array;
rawContentText: string;
size: number;
};

Response content of a GraphQL query.

Properties​

content​
readonly content: any;

The parsed and deserialized content.

rawContentBytes​
readonly rawContentBytes: Uint8Array;
rawContentText​
readonly rawContentText: string;
size​
readonly size: number;

GraphQlScriptSubscriptionCompletedContext​

type GraphQlScriptSubscriptionCompletedContext = {
};

Callback context of GraphQL subscription completed callback.


GraphQlScriptSubscriptionEventContext​

type GraphQlScriptSubscriptionEventContext = {
durationMillis: number;
response: GraphQlScriptQueryResponse;
};

Callback context of GraphQL subscription event callback.

Properties​

durationMillis​
readonly durationMillis: number;

Duration of the call in milliseconds.

response​
readonly response: GraphQlScriptQueryResponse;

The response.


HttpScriptStatus​

type HttpScriptStatus = {
code: number;
isSuccess: boolean;
reasonPhrase?: string;
};

Properties​

code​
readonly code: number;
isSuccess​
readonly isSuccess: boolean;
reasonPhrase?​
readonly optional reasonPhrase?: string;