Alokai

customMutation

Send an arbitrary GraphQL mutation to the Magento GraphQL endpoint For sending query, please see customQuery.

Signature

declare function customMutation<MUTATION = any,
	MUTATION_VARIABLES = any>(
	context: Context,
	input: {
  customHeaders?: CustomHeaders;
  fetchPolicy?: Extract<FetchPolicy,
	"network-only" | "no-cache">;
  mutation: string;
  mutationVariables: MUTATION_VARIABLES;
}
): Promise<FetchResult<MUTATION>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
{ customHeaders, fetchPolicy, mutation, mutationVariables }Required
inputRequired{ customHeaders?: CustomHeaders; fetchPolicy?: Extract<FetchPolicy, "network-only" | "no-cache">; mutation: string; mutationVariables: MUTATION_VARIABLES; }

Referenced Types

Examples

Simple usage:

import { sdk } from '~/sdk.config.ts';

// Prepare custom mutation
// Do not use gql-tag (gql``) here.
// For syntax highlighting (provided by respective IDE extensions), add the `#graphql` comment at the start of the template string
const mutation = `#graphql
 mutation generateCustomerToken($email: String!, $password: String!) {
   generateCustomerToken(email: $email, password: $password) {
     token
   }
 }
`;

// Prepare mutation variables
const mutationVariables = {
 email: TEST_USER_EMAIL,
 password: TEST_USER_PASSWORD
};

// use custom mutation and variables to fetch response adjusted to your needs
const result = await sdk.magento.customMutation({
 mutation,
 mutationVariables
});

On this page