Direct GraphQL access
For ad-hoc queries that aren't covered by a service:
import { GraphQLClient } from '@propeller-commerce/propeller-sdk-v2';
const client = new GraphQLClient({
endpoint: 'https://api.propeller.com/graphql',
securityMode: 'direct',
apiKey: 'your-api-key',
});
// Object-form arguments (preferred):
const result = await client.execute({
query: `query GetProducts($offset: Int!) {
products(input: { offset: $offset }) {
id
name
}
}`,
variables: { offset: 10 },
});
// Or higher-level helpers that throw on GraphQL errors:
const data = await client.query<{ viewer: { id: number } }>(
`query Viewer { viewer { id } }`
);
client.execute() never throws and always returns the raw { data, errors }.
The query / mutate helpers throw GraphQLOperationError on a hard failure —
see Error handling.
To attach per-operation transport hints (e.g. Next.js data-cache
revalidation), set fetchOptions on the operation object:
const result = await client.execute({
query: productDoc,
variables: { productId: 42 },
operationName: 'product',
fetchOptions: { next: { revalidate: 300, tags: ['catalog', 'product:42'] } },
});
See Per-operation cache hints for the type and Caching recipes for end-to-end patterns.