1.0.6 • Published 15 days ago

@aligent/bigcommerce-graphql-module v1.0.6

Weekly downloads
-
License
-
Repository
-
Last release
15 days ago

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 store
  • jwtPrivateKey - Random string used to encrypt JWT tokens
  • authToken - X-Auth-Token header value
  • clientSecret - BigCommerce API Client Secret
  • clientId - BigCommerce API Client ID
  • storeHash - 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

  1. 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
              }
            }
          }
        }
      `)
    );
  2. Re-Run the codegen to add your query to the SDK yarn run codegen

  3. Make your request!

    const response = sdk.customerAttribute({
      attributeId: 123,
    });