customQuery
Send an arbitrary GraphQL query to the Magento GraphQL endpoint For sending mutation, please see customMutation.
Signature
declare function customQuery<QUERY = any,
QUERY_VARIABLES = any>(
context: Context,
input: {
customHeaders?: CustomHeaders;
fetchPolicy?: FetchPolicy;
query: string;
queryVariables?: QUERY_VARIABLES;
}
): Promise<ApolloQueryResult<QUERY>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
{ customHeaders, fetchPolicy, query, queryVariables } | Required | ||
input | Required | { customHeaders?: CustomHeaders; fetchPolicy?: FetchPolicy; query: string; queryVariables?: QUERY_VARIABLES; } |
Referenced Types
- Context
- CustomHeaders
FetchPolicyApolloQueryResult
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// 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 query = `#graphql
query($search: String!) {
products(search: $search) {
items {
name
}
}
}
`;
const queryVariables: GetProductSearchParams = { search: "t-shirt" };
// fetch query response
const customQueryResult = await sdk.magento.customQuery({
query: query,
queryVariables
});If you want the method to send a GET instead of a POST request, use the options.clientConfig parameter.
const customQueryResult = await sdk.magento.customQuery(
{
query,
queryVariables
},
{
clientConfig: {
method: 'GET'
}
}
);