@omurilo/fastify-mercurius-auto-graphql
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

fastify-mercurius-auto-graphql

Statements Branches Functions Lines

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.

Package Sidebar

Install

npm i @omurilo/fastify-mercurius-auto-graphql

Weekly Downloads

5

Version

1.0.4

License

MIT

Unpacked Size

15.8 kB

Total Files

11

Last publish

Collaborators

  • omurilo