Coder Social home page Coder Social logo

franck-romano / mercurius Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mercurius-js/mercurius

1.0 1.0 0.0 571 KB

Implement GraphQL servers and gateways with Fastify

Home Page: https://mercurius.dev/

License: MIT License

JavaScript 97.00% HTML 0.90% Shell 0.03% TypeScript 2.08%

mercurius's Introduction

mercurius

CI workflow

Mercurius is a GraphQL adapter for Fastify

Features:

  • Caching of query parsing and validation.
  • Automatic loader integration to avoid 1 + N queries.
  • Just-In-Time compiler via graphql-jit.
  • Subscriptions.
  • Federation support.
  • Federated subscriptions support.
  • Gateway implementation, including Subscriptions.
  • Batched query support.
  • Customisable persisted queries.

Install

npm i fastify mercurius

The previous name of this module was fastify-gql (< 6.0.0).



Example

'use strict'

const Fastify = require('fastify')
const mercurius = require('mercurius')

const app = Fastify()

const schema = `
  type Query {
    add(x: Int, y: Int): Int
  }
`

const resolvers = {
  Query: {
    add: async (_, { x, y }) => x + y
  }
}

app.register(mercurius, {
  schema,
  resolvers
})

app.get('/', async function (req, reply) {
  const query = '{ add(x: 2, y: 2) }'
  return reply.graphql(query)
})

app.listen(3000)

See test.js for more examples, docs are coming.

makeExecutableSchema support

'use strict'

const Fastify = require('fastify')
const mercurius = require('mercurius')
const { makeExecutableSchema } = require('@graphql-tools/schema')

const app = Fastify()

const typeDefs = `
  type Query {
    add(x: Int, y: Int): Int
  }
`

const resolvers = {
  Query: {
    add: async (_, { x, y }) => x + y
  }
}

app.register(mercurius, {
  schema: makeExecutableSchema({ typeDefs, resolvers })
})

app.get('/', async function (req, reply) {
  const query = '{ add(x: 2, y: 2) }'
  return reply.graphql(query)
})

app.listen(3000)

Context

More info

API

More info

Federation

More info

Subscriptions

More info

Batched Queries

More info

Persisted Queries

More info

Plugins

More info

Integrations

More info

Acknowledgements

The project is kindly sponsored by:

The Mercurius name was gracefully donated by Marco Castelluccio. The usage of that library was described in https://hacks.mozilla.org/2015/12/web-push-notifications-from-irssi/, and you can find that codebase in https://github.com/marco-c/mercurius.

License

MIT

mercurius's People

Contributors

mcollina avatar pacodu avatar greenkeeper[bot] avatar frikille avatar pabloszx avatar aldis-ameriks avatar iviaks avatar dependabot-preview[bot] avatar rafaelgss avatar pscarey avatar leorossi avatar skellla avatar jemikanegara avatar john-behan avatar yndc avatar gtolarc avatar mafintosh avatar jonnydgreen avatar hw13 avatar admataz avatar proti avatar salmanm avatar santiagoalmeidabolannos avatar sastan avatar asciidisco avatar shogunpanda avatar simoneb avatar stephenh avatar strongermyself avatar thbp avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.