Configure GraphQL Code Generator#
Mesh relies on GraphQL Code Generator to generate the Resolvers
type that give you access to:
- fully typed resolvers map
- fully typed SDK (through the
context
) to fetch data from Sources
The generated typed Mesh SDK can also be accessed directly, as shown below:
import { getMeshSdk } from './.mesh';
async function test() {
// Load mesh config and get the sdkClient from it
const sdk = getMeshSdk();
// Execute `myQuery` and get a type-safe result
// Variables and result are typed: { getSomething: { fieldA: string, fieldB: number }, errors?: GraphQLError[] }
const { getSomething } = await sdk.myQuery({ someVar: 'foo' });
}
GraphQL Code Generator default configuration#
Mesh provides a default GraphQL Code Generator configuration, shown below:
{
"skipTypename": true,
"flattenGeneratedTypes": false,
"onlyOperationTypes": false,
"preResolveTypes": false,
"namingConvention": "keep",
"documentMode": "graphQLTag",
"gqlImport": "@graphql-mesh/utils#gql",
"enumsAsTypes": true,
"ignoreEnumValuesFromSchema": true,
"useIndexSignature": true,
"contextType": "MeshContext",
}
Customizing the GraphQL Code Generator configuration#
The above default configuration can be override with the codegen
root parameter, as shown below:
codegen:
skipTypename: false
contextType: "./context#MyContextType"
Please note, that the codegen
parameter allows you to update the configuration passed to the GraphQL Code Generator plugins used by Mesh:
The codegen
parameter won't allow you to add or remove plugins.