Skip to content

Commit 78f8282

Browse files
authored
Merge pull request graphql#1162 from Eomm/patch-1
add: mercurius server module
2 parents c63454b + 302632d commit 78f8282

File tree

1 file changed

+45
-0
lines changed
  • src/content/code/language-support/javascript/server

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Mercurius
3+
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.
4+
url: https://mercurius.dev/
5+
github: mercurius-js/mercurius
6+
npm: "mercurius"
7+
---
8+
9+
To run an hello world script with `mercurius`:
10+
11+
```bash
12+
npm install fastify mercurius
13+
```
14+
15+
Then run `node app.js` with this code in `app.js`:
16+
17+
```js
18+
const Fastify = require('fastify')
19+
const mercurius = require('mercurius')
20+
21+
const schema = `
22+
type Query {
23+
hello(name: String): String!
24+
}
25+
`
26+
27+
const resolvers = {
28+
Query: {
29+
hello: async (_, { name }) => `hello ${name || 'world'}`
30+
}
31+
}
32+
33+
const app = Fastify()
34+
app.register(mercurius, {
35+
schema,
36+
resolvers
37+
})
38+
39+
app.listen(3000)
40+
41+
// Call IT!
42+
// curl 'http://localhost:3000/graphql' \
43+
// -H 'content-type: application/json' \
44+
// --data-raw '{"query":"{ hello(name:\"Marcurius\") }" }'
45+
```

0 commit comments

Comments
 (0)