Skip to content

Add graphql-yoga server code sample to code #922

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

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 37 additions & 0 deletions src/content/code/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,43 @@ app.listen({ port: 4000 }, () =>

Apollo Server also supports all Node.js HTTP server frameworks: Express, Connect, HAPI, Koa and NestJs.

#### [graphql-yoga](https://github.com/prisma-labs/graphql-yoga) ([github](https://github.com/apollographql/apollo-server)) ([npm](https://www.npmjs.com/package/graphql-yoga))

Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience

- Sensible defaults & includes everything you need with minimal setup.
- Built-in support for GraphQL subscriptions using WebSockets.
- Works with all GraphQL clients (Apollo, Relay...) and fits seamless in your GraphQL workflow.

To run a hello world server with graphql-yoga:

```bash
npm install graphql-yoga
```

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

```js
import { GraphQLServer } from 'graphql-yoga'
// ... or using "require()"
// const { GraphQLServer } = require('graphql-yoga')

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

const resolvers = {
Query: {
hello: (_, { name }) => `Hello \${name || 'World'}`,
},
};

const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))
```

### Kotlin

- [graphql-kotlin](https://github.com/ExpediaGroup/graphql-kotlin/): A set of libraries for running GraphQL server in Kotlin.
Expand Down