Skip to content

add: mercurius server module #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/content/code/language-support/javascript/server/mercurius.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Mercurius
description: Mercurius is a flexible and extendible GraphQL adapter for Fastify, a blazing-fast web framework with the least overhead and a powerful plugin architecture.
url: https://mercurius.dev/
github: mercurius-js/mercurius
npm: "mercurius"
---

To run an hello world script with `mercurius`:

```bash
npm install fastify mercurius
```

Then run `node app.js` with this code in `app.js`:

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

const schema = `
type Query {
hello(name: String): String!
}
`

const resolvers = {
Query: {
hello: async (_, { name }) => `hello ${name || 'world'}`
}
}

const app = Fastify()
app.register(mercurius, {
schema,
resolvers
})

app.listen(3000)

// Call IT!
// curl 'http://localhost:3000/graphql' \
// -H 'content-type: application/json' \
// --data-raw '{"query":"{ hello(name:\"Marcurius\") }" }'
```