|
1 | 1 | --- |
2 | 2 | name: graphql-yoga |
3 | | -description: Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience |
| 3 | +description: GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL Server using Envelop and GraphQL Tools. |
4 | 4 | url: https://github.com/dotansimha/graphql-yoga |
5 | 5 | github: dotansimha/graphql-yoga |
6 | | -npm: "graphql-yoga" |
| 6 | +npm: "@graphql-yoga/node" |
7 | 7 | --- |
8 | 8 |
|
9 | | -- Sensible defaults & includes everything you need with minimal setup. |
10 | | -- Built-in support for GraphQL subscriptions using WebSockets. |
11 | | -- Works with all GraphQL clients (Apollo, Relay...) and fits seamless in your GraphQL workflow. |
| 9 | +- Built around the Fetch API `Request` & `Response` objects |
| 10 | +- GraphQL over HTTP compliant |
| 11 | +- Extensible GraphQL Engine powered by Envelop |
| 12 | +- GraphQL Subscriptions over HTTP |
| 13 | +- Handle file uploads with GraphQL |
| 14 | +- Integrates with AWS Lambda, Cloudflare Workers, Deno, Express, Next.js, SvelteKit, and more. |
12 | 15 |
|
13 | 16 | To run a hello world server with graphql-yoga: |
14 | 17 |
|
15 | 18 | ```bash |
16 | | -npm install graphql-yoga |
| 19 | +npm install @graphql-yoga/node graphql |
17 | 20 | ``` |
18 | 21 |
|
19 | | -Then run `node server.js` with this code in `server.js`: |
| 22 | +Then create a server using the `createServer` import: |
20 | 23 |
|
21 | 24 | ```js |
22 | | -import { GraphQLServer } from 'graphql-yoga' |
23 | | -// ... or using "require()" |
24 | | -// const { GraphQLServer } = require('graphql-yoga') |
25 | | -const typeDefs = ` |
26 | | - type Query { |
27 | | - hello(name: String): String! |
28 | | - } |
29 | | -`; |
30 | | -const resolvers = { |
31 | | - Query: { |
32 | | - hello: (_, { name }) => `Hello ${name || 'World'}`, |
| 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', |
| 37 | + }, |
| 38 | + }, |
33 | 39 | }, |
34 | | -}; |
35 | | -const server = new GraphQLServer({ typeDefs, resolvers }) |
36 | | -server.start(() => console.log('Server is running on localhost:4000')) |
| 40 | +}) |
| 41 | + |
| 42 | +server.start() |
37 | 43 | ``` |
| 44 | + |
| 45 | +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