1.0.6 • Published 2 months ago
@aligent/bigcommerce-graphql-module v1.0.6
BigCommerce GraphQl Module
Configuration
The configuration interface is found here: packages/modules/bigcommerce/src/index.ts
and currently contains these properties:
graphqlEndpoint
- BigCommerce Graphql endpoint for your storejwtPrivateKey
- Random string used to encrypt JWT tokensauthToken
- X-Auth-Token header valueclientSecret
- BigCommerce API Client SecretclientId
- BigCommerce API Client IDstoreHash
- BigCommerce Store hash
Fetching config in a resolver:
import { ModuleConfig } from '../../providers';
export const someResolver: QueryResolvers['a-resolver-type'] = {
resolve: async (_root, _args, context, _info) => {
const config = context.injector.get(ModuleConfig);
return {};
},
};
Fetching config in a class:
import { ModuleConfig } from '../../providers';
import { BigCommerceModuleConfig } from '@aligent/bigcommerce-graphql-module';
@Injectable({})
export class SomeService {
constructor(@Inject(ModuleConfig) private config: BigCommerceModuleConfig) {}
getGraphQlEndpoint() {
return this.config.graphqlEndpoint;
}
}
The BigCommerce GraphQl SDK
Fetching the sdk in a resolver:
import { BigCommerceSdk } from '../../providers';
import { Sdk } from '@aligent/bigcommerce-operations';
export const someResolver: QueryResolvers['a-resolver-type'] = {
resolve: async (_root, _args, context, _info) => {
const sdk: Sdk = context.injector.get(BigCommerceSdk);
const response = sdk.login({
email,
password,
});
return {};
},
};
Adding new queries to the Sdk
Write out your gql query in a new file in
packages/modules/bigcommerce/src/apis/graphql/requests/
import { gql } from 'graphql-tag'; import { stripIgnoredCharacters } from 'graphql/utilities/stripIgnoredCharacters'; import { print } from 'graphql/index'; export const customerAttribute = stripIgnoredCharacters( print(gql` query customerAttribute($attributeId: Int!) { customer { attributes { attribute(entityId: $attributeId) { entityId name value } } } } `) );
Re-Run the codegen to add your query to the SDK
yarn run codegen
Make your request!
const response = sdk.customerAttribute({ attributeId: 123, });