@omurilo/fastify-mercurius-auto-graphql
v1.0.4
Published
Fastify Mercurius Auto Generate Graphql Schema plugin from Swagger/OpenAPI specs
Downloads
2
Maintainers
Readme
fastify-mercurius-auto-graphql
A Fastify
Mercurius auto GraphQL
schema from Swagger/OpenAPI specs plugin integration.
Getting started
yarn add @omurilo/fastify-mercurius-auto-graphql
Next, set up the plugin
- Swagger OpenAPI auto GraphQL schema:
import fp from 'fastify-plugin'
import type { FastifyMercuriusAutoGraphqlOptions } from '@omurilo/fastify-mercurius-auto-graphql'
import fastifyMercuriusAutoGraphqlPlugin from '@omurilo/fastify-mercurius-auto-graphql'
export default fp<FastifyMercuriusAutoGraphqlOptions>(
async fastify => {
await fastify.register(fastifyMercuriusAutoGraphqlPlugin, {
graphql: {
viewer: false,
},
customizeHttpRequest(opts, context) {
opts.headers.authorization = context.reply.request.headers.authorization
return opts
},
})
},
{ name: 'mercurius-auto-graphql' },
)
- Specify
GraphQL
schema:
import fp from 'fastify-plugin'
import type { FastifyMercuriusAutoGraphqlOptions } from '@omurilo/fastify-mercurius-auto-graphql'
import fastifyMercuriusAutoGraphqlPlugin from '@omurilo/fastify-mercurius-auto-graphql'
export default fp<FastifyMercuriusAutoGraphqlOptions>(
async (fastify) => {
await fastify.register(fastifyMercuriusAutoGraphqlPlugin, {
graphql: {
viewer: false,
},
mercurius: {
schema: `
type Query {
dummy: Int
}
`
},
customizeHttpRequest(opts, context) {
opts.headers.authorization = context.reply.request.headers.authorization
return opts
}
})
},
{ name: 'mercurius-auto-graphql' },
)
Mercurius Documentation
Read the documentation at Mercurius
ESM Only
This package only supports being directly imported in the ESM context.
For information on how to use it in a CommonJS context, please check this page.