GraphQL Mesh is a framework that helps shape and build an executable GraphQL schema from multiple data sources.
@graphcommerce/graphql-mesh/meshConfig method which allows you to create
plugins for the mesh configurationadditionalTypeDefs, additionalResolver, sources.handlers.openapi.source
accept module patterns @graphcommerce/my-package/resolver.ts*.graphqls files are automatically loaded from the project root.schema/**/*.graphqls are automatically loaded.schema246 / schema247 etc. folders.To make modifications to the Mesh configuration, you can:
You can always modify the base configuration of the Mesh by modifying the
meshrc.yaml file. After making always run yarn codegen (this can be in a
separate terminal and nextjs will reload it).
import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
export const config: PluginConfig = {
module: '@graphcommerce/graphql-mesh/meshConfig',
type: 'function',
}
export const meshConfig: FunctionPlugin<typeof meshConfigBase> = (
prev,
baseConfig,
graphCommerceConfig,
) => {
prev({
...baseConfig,
sources: [
...baseConfig.sources,
{
name: 'mySource',
handler: {
graphql: {
endpoint: 'https://my-source.com/graphql',
},
},
},
],
additionalResolvers: [
...(baseConfig.additionalResolvers ?? []),
'lib/resolvers/my-feature.ts',
],
})
}
During development it might come in handy to write schema extensions even before
any backend work has been done. AnyFile.graphqls in the graphql directory will
automatically be picked up and merged with the rest of the schema.
In the plugin add additionalResolvers and point to your ts file where the resolver is.
// This MUST be a type import, else there will be a circular dependency.
import type { Resolvers } from '@graphcommerce/graphql-mesh'
const resolvers: Resolvers = {}
To make sure changes are picked up during development set the config value
graphqlMeshEditMode: true in your graphcommerce.config.js or set the env
variable GC_GRAPHQL_MESH_EDIT_MODE=1. This will make the frontend
considerably slower.