Friends Of AdonisFriends Of Adonis

Configuration

Emitting Schema

It is possible to automatically emit the generated GraphQL schema using the emitSchemaFile configuration option. This might be useful for generating client without relying on schema introspection or for working in "schema-first".

config/graphql.ts
import { defineConfig } from '@foadonis/graphql'
 
export default defineConfig({
  emitSchemaFile: true, 
  // ...rest of your config
})

By default it will generate a schema.gql file at the root of your application but you might want to define a specific path.

config/graphql.ts
import path from 'node:path'
import { defineConfig } from '@foadonis/graphql'
 
export default defineConfig({
  emitSchemaFile: path.resolve(import.meta.dirname, '__snapshots__/schema/schema.graphql'), 
  // ...rest of your config
})

You can read more about schema emitting on the TypeGraphQL documentation.

Introspection and Playground

It’s often useful to ask a GraphQL schema for information about what queries it supports. GraphQL allows you to do so using the introspection system.

It is highly recommended to not enable introspection in production for security reasons as it exposes the available operation of your Application.

You can use the apollo.introspection and apollo.playground options in your GraphQL configuration file:

config/graphql.ts
import { defineConfig } from '@foadonis/graphql'
 
export default defineConfig({
  apollo: {
    playground: true, 
    introspection: true, 
  },
})

Apollo Server options

The apollo option of your GraphQL configuration is merged with the options provided by @foadonis/graphql allowing you to extend the capabilies of the ApolloServer. You can for example add plugins.

import { defineConfig } from '@foadonis/graphql'
import { ApolloServerPluginUsageReporting } from '@apollo/server/plugin/usageReporting'
import MyCustomScalar from '#graphql/scalars/my_custom_scalar.ts'
 
export default defineConfig({
  apollo: {
    plugins: [
      ApolloServerPluginUsageReporting({
        sendVariableValues: { all: true },
      }),
    ],
  },
})

Schema Generation Options

Your GraphQL configuration is merged with the options used to generate the GraphQL schema allowing you to extend the capabilies of your schema. For example you might want to add Custom scalars.

import { defineConfig } from '@foadonis/graphql'
import MyCustomScalar from '#graphql/scalars/my_custom_scalar.ts'
 
export default defineConfig({
  scalarsMap: [MyCustomScalar], 
})

You can find more information about the available options on the Official TypeGraphQL documentation

On this page