feat(saleor): Phase 1 - GraphQL Client Setup
- Add Apollo Client for Saleor GraphQL API - Create GraphQL fragments (Product, Variant, Checkout) - Create GraphQL queries (Products, Checkout) - Create GraphQL mutations (Checkout operations) - Add TypeScript types for Saleor entities - Add product helper functions - Install @apollo/client and graphql dependencies Part of WordPress/WooCommerce → Saleor migration
This commit is contained in:
49
src/lib/saleor/client.ts
Normal file
49
src/lib/saleor/client.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client";
|
||||
import { setContext } from "@apollo/client/link/context";
|
||||
|
||||
const httpLink = createHttpLink({
|
||||
uri: process.env.NEXT_PUBLIC_SALEOR_API_URL || "http://localhost:8000/graphql/",
|
||||
});
|
||||
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
// Saleor doesn't require auth for public queries
|
||||
// Add auth token here if needed for admin operations
|
||||
return {
|
||||
headers: {
|
||||
...headers,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const saleorClient = new ApolloClient({
|
||||
link: authLink.concat(httpLink),
|
||||
cache: new InMemoryCache({
|
||||
typePolicies: {
|
||||
Query: {
|
||||
fields: {
|
||||
products: {
|
||||
keyArgs: ["channel", "filter"],
|
||||
merge(existing, incoming) {
|
||||
if (!existing) return incoming;
|
||||
return {
|
||||
...incoming,
|
||||
edges: [...existing.edges, ...incoming.edges],
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
fetchPolicy: "cache-first",
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: "cache-first",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default saleorClient;
|
||||
Reference in New Issue
Block a user