Alokai

route

Resolve a route object data

Signature

declare function route(
	context: Context,
	url: string,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<Route>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
urlRequiredstring
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

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

// fetch route object data
const result = await sdk.magento.route({
  url: 'aether-gym-pant.html'
});

// Example result:
{
   data: {
     route: { type: 'PRODUCT', sku: 'MP11', __typename: 'ConfigurableProduct' }
   },
   loading: false,
   networkStatus: 7
}

Creating a custom GraphQL query to fetch additional data:

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'route-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             query route($url: String!) {
               route(url: $url) {
                 ${metadata?.fields}
               }
             }
           }`
        }),
      },
    }
  }
};

Using a custom GraphQL query created in the previous example.

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

// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
  route: 'route-custom-query',
  metadata: {
    fields: 'type ... on CategoryInterface { uid name image}' // fetch additional name and image fields
  }
};

// data will contain only the fields specified in the custom query.
const { data } = await sdk.magento.route({ url: 'women.html' }, customQuery);

On this page