You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/pages/getting-started.mdx
+42-9Lines changed: 42 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@ title: Getting Started With GraphQL.js
3
3
sidebarTitle: Getting Started
4
4
---
5
5
6
+
import { Tabs } from'nextra/components';
7
+
6
8
{/* title can be removed in Nextra 4, since sidebar title will take from first h1 */}
7
9
8
10
# Getting Started With GraphQL.js
@@ -19,7 +21,7 @@ and arrow functions, so if you aren't familiar with them you might want to read
19
21
20
22
To create a new project and install GraphQL.js in your current directory:
21
23
22
-
```bash
24
+
```sh npm2yarn
23
25
npm init
24
26
npm install graphql --save
25
27
```
@@ -28,18 +30,16 @@ npm install graphql --save
28
30
29
31
To handle GraphQL queries, we need a schema that defines the `Query` type, and we need an API root with a function called a “resolver” for each API endpoint. For an API that just returns “Hello world!”, we can put this code in a file named `server.js`:
Copy file name to clipboardExpand all lines: website/pages/running-an-express-graphql-server.mdx
+77-1Lines changed: 77 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,90 @@ title: Running an Express GraphQL Server
3
3
sidebarTitle: Running Express + GraphQL
4
4
---
5
5
6
+
import { Tabs } from'nextra/components';
7
+
6
8
The simplest way to run a GraphQL API server is to use [Express](https://expressjs.com), a popular web application framework for Node.js. You will need to install two additional dependencies:
7
9
8
-
```bash
10
+
```sh npm2yarn
9
11
npm install express graphql-http graphql --save
10
12
```
11
13
12
14
Let's modify our “hello world” example so that it's an API server rather than a script that runs a single query. We can use the 'express' module to run a webserver, and instead of executing a query directly with the `graphql` function, we can use the `graphql-http` library to mount a GraphQL API server on the “/graphql” HTTP endpoint:
0 commit comments