Skip to content

Commit c3e8955

Browse files
authored
Update GraphQL Yoga recipe (#1313)
1 parent d08a666 commit c3e8955

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/content/code/language-support/javascript/server/graphql-yoga.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: graphql-yoga
33
description: GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL Server using Envelop and GraphQL Tools.
44
url: https://github.com/dotansimha/graphql-yoga
55
github: dotansimha/graphql-yoga
6-
npm: "@graphql-yoga/common"
6+
npm: "graphql-yoga"
77
---
88

99
- Built around the Fetch API `Request` & `Response` objects
@@ -16,30 +16,33 @@ npm: "@graphql-yoga/common"
1616
To run a hello world server with graphql-yoga:
1717

1818
```bash
19-
npm install @graphql-yoga/node graphql
19+
npm install graphql-yoga graphql
2020
```
2121

2222
Then create a server using the `createServer` import:
2323

2424
```js
25-
import { createServer } from '@graphql-yoga/node'
26-
27-
const server = createServer({
28-
schema: {
29-
typeDefs: /* GraphQL */ `
30-
type Query {
31-
hello: String
32-
}
33-
`,
34-
resolvers: {
35-
Query: {
36-
hello: () => 'Hello Hello Hello',
25+
import { createServer } from 'http'
26+
import { createSchema, createYoga } from 'graphql-yoga'
27+
28+
createServer(
29+
createYoga({
30+
schema: createSchema({
31+
typeDefs: /* GraphQL */ `
32+
type Query {
33+
hello: String
34+
}
35+
`,
36+
resolvers: {
37+
Query: {
38+
hello: () => 'Hello Hello Hello',
39+
},
3740
},
38-
},
39-
},
41+
})
42+
})
43+
).listen(4000, () => {
44+
console.info('GraphQL Yoga is listening on http://localhost:4000/graphql')
4045
})
41-
42-
server.start()
4346
```
4447

4548
Depending on your deployment target, you may need to use an additional library. See the [documentation](https://www.graphql-yoga.com/docs) for further details.

0 commit comments

Comments
 (0)