Contains objects used to interact with the Storefront API. This object is returned as part of different contexts, such as [`appProxy`](/docs/api/shopify-app-remix/authenticate/public/app-proxy), and [`unauthenticated.storefront`](/docs/api/shopify-app-remix/unauthenticated/unauthenticated-storefront).
Provides utilities that apps can use to make requests to the Storefront API.
Method for interacting with the Shopify Storefront GraphQL API If you're getting incorrect type hints in the Shopify template, follow [these instructions](https://github.com/Shopify/shopify-app-template-remix/tree/main#incorrect-graphql-hints).
query: Operation extends keyof Operations
options: GraphQLQueryOptions<Operation, Operations>
export type GraphQLClient<Operations extends AllOperations> = < Operation extends keyof Operations, >( query: Operation, options?: GraphQLQueryOptions<Operation, Operations>, ) => Promise<GraphQLResponse<Operation, Operations>>;
The version of the API to use for the request.
Additional headers to include in the request.
The total number of times to try the request if it fails.
The variables to pass to the operation.
Contains objects used to interact with the Storefront API. This object is returned as part of different contexts, such as [`appProxy`](/docs/api/shopify-app-remix/authenticate/public/app-proxy), and [`unauthenticated.storefront`](/docs/api/shopify-app-remix/unauthenticated/unauthenticated-storefront).
import { json } from "@remix-run/node";
import { authenticate } from "../shopify.server";
export async function action({ request }: ActionFunctionArgs) {
const { storefront } = await authenticate.public.appProxy(request);
const response = await storefront.graphql(`{blogs(first: 10) { edges { node { id } } } }`);
return json(await response.json());
}
import { ActionFunctionArgs } from "@remix-run/node";
import { authenticate } from "../shopify.server";
export const action = async ({ request }: ActionFunctionArgs) => {
const { storefront } = await authenticate.public.appProxy(request);
try {
const response = await storefront.graphql(
`#graphql
query incorrectQuery {
products(first: 10) {
nodes {
not_a_field
}
}
}`,
);
return json({ data: await response.json() });
} catch (error) {
if (error instanceof GraphqlQueryError) {
// { errors: { graphQLErrors: [
// { message: "Field 'not_a_field' doesn't exist on type 'Product'" }
// ] } }
return json({ errors: error.body?.errors }, { status: 500 });
}
return json({ message: "An error occurred" }, { status: 500 });
}
}
import { shopifyApp } from "@shopify/shopify-app-remix/server";
const shopify = shopifyApp({
// ...
});
export default shopify;
export const authenticate = shopify.authenticate;