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
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
{ customHeaders, fetchPolicy, mutation, mutationVariables } | Required | ||
input | Required | { customHeaders?: CustomHeaders; fetchPolicy?: Extract<FetchPolicy, "network-only" | "no-cache">; mutation: string; mutationVariables: MUTATION_VARIABLES; } |
Referenced Types
- Context
- CustomHeaders
FetchPolicyFetchResult
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
});