Skip to content

Update GraphQL Yoga recipe #1313

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
Nov 17, 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
39 changes: 21 additions & 18 deletions src/content/code/language-support/javascript/server/graphql-yoga.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: graphql-yoga
description: GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL Server using Envelop and GraphQL Tools.
url: https://github.com/dotansimha/graphql-yoga
github: dotansimha/graphql-yoga
npm: "@graphql-yoga/common"
npm: "graphql-yoga"
---

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

```bash
npm install @graphql-yoga/node graphql
npm install graphql-yoga graphql
```

Then create a server using the `createServer` import:

```js
import { createServer } from '@graphql-yoga/node'

const server = createServer({
schema: {
typeDefs: /* GraphQL */ `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello Hello Hello',
import { createServer } from 'http'
import { createSchema, createYoga } from 'graphql-yoga'

createServer(
createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello Hello Hello',
},
},
},
},
})
})
).listen(4000, () => {
console.info('GraphQL Yoga is listening on http://localhost:4000/graphql')
})

server.start()
```

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.