Skip to content

Commit 216eae6

Browse files
committed
Add graphql-yoga code sample to code
1 parent 24f7de4 commit 216eae6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/content/code/code.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,43 @@ app.listen({ port: 4000 }, () =>
320320

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

323+
#### [graphql-yoga](https://github.com/prisma-labs/graphql-yoga) ([github](https://github.com/apollographql/apollo-server)) ([npm](https://www.npmjs.com/package/graphql-yoga))
324+
325+
Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
326+
327+
- Sensible defaults & includes everything you need with minimal setup.
328+
- Built-in support for GraphQL subscriptions using WebSockets.
329+
- Works with all GraphQL clients (Apollo, Relay...) and fits seamless in your GraphQL workflow.
330+
331+
To run a hello world server with graphql-yoga:
332+
333+
```bash
334+
npm install graphql-yoga
335+
```
336+
337+
Then run `node server.js` with this code in `server.js`:
338+
339+
```js
340+
import { GraphQLServer } from 'graphql-yoga'
341+
// ... or using "require()"
342+
// const { GraphQLServer } = require('graphql-yoga')
343+
344+
const typeDefs = `
345+
type Query {
346+
hello(name: String): String!
347+
}
348+
`;
349+
350+
const resolvers = {
351+
Query: {
352+
hello: (_, { name }) => `Hello \${name || 'World'}`,
353+
},
354+
};
355+
356+
const server = new GraphQLServer({ typeDefs, resolvers })
357+
server.start(() => console.log('Server is running on localhost:4000'))
358+
```
359+
323360
### Kotlin
324361

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

0 commit comments

Comments
 (0)