GraphQL context

Front-Commerce’s GraphQL modules can register GraphQL schema extensions and resolvers to actually fetch the data. Front-Commerce manages a context object and makes it available in the GraphQL schema so resolvers can use it using standard GraphQL mechanisms.

To get started with GraphQL modules, we recommend you to read the Extend the GraphQL schema documentation page.

This page contains the different keys available in the GraphQL context object managed by Front-Commerce.

loaders

The loaders key contains all the loaders registered by GraphQL modules, from their contextEnhancer module definition method.

Example :

// my-module/server/modules/clicks-counters/resolvers.js
module.exports = {
  Product: {
    clicksCounter: ({ sku }, _, context) => {
      return context.loaders.Counter.loadBySku(sku);
    }
  }
}

See Slim down resolvers with loaders to understand how to leverage this value.

req

The req key contains the current HTTP request (from Express server) having triggered the GraphQL query.

It could be useful in some specific cases, but we generally recommend NOT TO use it directly. Resolvers should to use loaders instead.

One of the reason why it has been introduced in the core, is to allow context customization in Remote schema stitching scenarii. See linkContextBuilders for an usage example.

Edit on GitHub