Gateway Modules
Modules found in src/backend/graphql/modules
are "local" gateway modules – actual GraphQL types and resolvers implementations that live on the API gateway lambda. These modules can be used to add entirely custom schemas, or to extend schemas defined by external schemas or even other gateway modules.
Gateway modules are used when we want to extend the GraphQL schema to embrace an external API that isn't GraphQL.
Automatic discovery
GraphQL modules within this directory are automatically discovered.
- The directory name is the ID of the module
- Every module MUST have a single schema file at
./[module]/[module].graphql
This processed is achieved using Webpack's require.context
, and is done in the ./index.ts file.
Resolvers
Every module CAN define resolvers, which should live in a ./[module]/resolvers
directory. Resolver files can either define resolvers for a whole GraphQL type, or for a single field:
Type resolver:
- Allowed patterns:
./[module]/resolvers/[type].ts
./[module]/resolvers/[type]/index.ts
- Export pattern:
- Single default export object containing the type's field resolvers.
Single field resolver:
- Allowed patterns:
./[module]/resolvers/[type].[field].ts
./[module]/resolvers/[type]/[field].ts
./[module]/resolvers/[type].[field]/index.ts
./[module]/resolvers/[type]/[field]/index.ts
- Export pattern:
- Single default export with the resolver
Middlewares
Resolver files can also export a middleware
:
Type resolver: must be an object, with keys mapping fields, with a middleware array as value.
Single field resolver: must be an array of middlewares.
See this documentation to understand how middlewares work.