Axios instances
This reference explains how to create `axios` instances to interact with Magento's API.
makeAdminClientFromRequest
The makeAdminClientFromRequest
function creates an axios
instance that can
be used to interact with Magento's API as an Admin.
makeAdminClientFromRequest(request);
Arguments:
Name | Type | Description |
---|---|---|
request | Request | v2 compatible request object |
Example:
import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeAdminClientFromRequest } from "@front-commerce/magento1/axios";
export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const adminAxiosInstance = makeAdminClientFromRequest(req);
// rest of logic
},
});
makeAuthServiceFromRequest
The makeAuthServiceFromRequest
function creates a service that expose related
session information.
makeAuthServiceFromRequest(request);
Arguments:
Name | Type | Description |
---|---|---|
request | Request | v2 compatible request object |
Example:
import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeAuthServiceFromRequest } from "@front-commerce/magento1/axios";
export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const authService = makeAuthServiceFromRequest(req);
// rest of logic
},
});
makeUserClientFromRequest
The makeUserClientFromRequest
function creates an axios
instance that can be
used to interact with Magento's API as a customer.
makeUserClientFromRequest(request);
Arguments:
Name | Type | Description |
---|---|---|
request | Request | v2 compatible request object |
Example:
import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeUserClientFromRequest } from "@front-commerce/magento1/axios";
export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const axiosInstance = makeUserClientFromRequest(req);
// rest of logic
},
});
makeCartUrlBuilderFromRequest
The makeCartUrlBuilderFromRequest
function creates a CartUrlBuilder
instance.
makeCartUrlBuilderFromRequest(request);
Arguments:
Name | Type | Description |
---|---|---|
request | Request | v2 compatible request object |
Example:
import { createGraphQLRuntime } from "@front-commerce/core/graphql";
import { makeCartUrlBuilderFromRequest } from "@front-commerce/magento1/axios";
export default createGraphQLRuntime({
contextEnhancer: ({ req }) => {
const cartUrlBuilder = makeCartUrlBuilderFromRequest(req);
// rest of logic
},
});
makeFilterParams
The makeFilterParams
function creates a filter for Magento API request to
filter on properties.
makeFilterParams(filters, initialFilters);
Arguments:
Name | Type | Description |
---|---|---|
filters | object[] | Array of filters |
initialFilters | object[] | Initial filters computed by other means |
Example:
import { makeFilterParams } from "@front-commerce/magento1/axios";
const params = makeFilterParams([{ code: "is_filterable", value: "1" }], {
initialParams: { limit: 0 },
});
makeSkuFilters
The makeSkuFilters
function creates a filter for Magento API request to filter
on SKU.
makeSkuFilters(skus);
Arguments:
Name | Type | Description |
---|---|---|
skus | string[] | Array of SKU |
code | string | Filter code (default to sku ) |
Example:
import { makeSkuFilters } from "@front-commerce/magento1/axios";
const filter = makeSkuFilters(["sku1", "sku2", "sku3"]);