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/index.mdx
+64-27Lines changed: 64 additions & 27 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
@@ -16,7 +18,7 @@ and arrow functions, so if you aren't familiar with them you might want to read
16
18
17
19
To create a new project and install GraphQL.js in your current directory:
18
20
19
-
```bash
21
+
```sh npm2yarn
20
22
npm init
21
23
npm install graphql --save
22
24
```
@@ -25,32 +27,67 @@ npm install graphql --save
25
27
26
28
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`:
27
29
28
-
```javascript
29
-
let { graphql, buildSchema } =require('graphql');
30
-
31
-
// Construct a schema, using GraphQL schema language
32
-
let schema =buildSchema(`
33
-
type Query {
34
-
hello: String
35
-
}
36
-
`);
37
-
38
-
// The rootValue provides a resolver function for each API endpoint
39
-
let rootValue = {
40
-
hello() {
41
-
return'Hello world!';
42
-
},
43
-
};
44
-
45
-
// Run the GraphQL query '{ hello }' and print out the response
0 commit comments