Skip to content

Commit a3e172a

Browse files
committed
Provide people with tabs so they can use classes as well
1 parent 84a49f7 commit a3e172a

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

website/pages/index.mdx

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Getting Started With GraphQL.js
33
sidebarTitle: Getting Started
44
---
55

6+
import { Tabs } from 'nextra/components';
7+
68
{/* title can be removed in Nextra 4, since sidebar title will take from first h1 */}
79

810
# 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
1618

1719
To create a new project and install GraphQL.js in your current directory:
1820

19-
```bash
21+
```sh npm2yarn
2022
npm init
2123
npm install graphql --save
2224
```
@@ -25,18 +27,48 @@ npm install graphql --save
2527

2628
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`:
2729

28-
```javascript
29-
let { graphql, buildSchema } = require('graphql');
30+
<Tabs items={['Template', 'Classes']}>
31+
<Tabs.Tab>
32+
```javascript
33+
const { graphql, buildSchema } = require('graphql');
3034

3135
// Construct a schema, using GraphQL schema language
32-
let schema = buildSchema(`
33-
type Query {
34-
hello: String
35-
}
36-
`);
36+
const schema = buildSchema(` type Query { hello: String } `);
37+
38+
// The rootValue provides a resolver function for each API endpoint
39+
const rootValue = {
40+
hello() {
41+
return 'Hello world!';
42+
},
43+
};
44+
45+
// Run the GraphQL query '{ hello }' and print out the response
46+
graphql({
47+
schema,
48+
source: '{ hello }',
49+
rootValue,
50+
}).then((response) => {
51+
console.log(response);
52+
});
53+
54+
````
55+
</Tabs.Tab>
56+
<Tabs.Tab>
57+
```javascript
58+
const { graphql, buildSchema } = require('graphql');
59+
60+
// Construct a schema
61+
const schema = new GraphQLSchema({
62+
query: new GraphQLObjectType({
63+
name: 'Query',
64+
fields: {
65+
hello: { type: GraphQLString },
66+
},
67+
}),
68+
});
3769
3870
// The rootValue provides a resolver function for each API endpoint
39-
let rootValue = {
71+
const rootValue = {
4072
hello() {
4173
return 'Hello world!';
4274
},
@@ -50,7 +82,10 @@ graphql({
5082
}).then((response) => {
5183
console.log(response);
5284
});
53-
```
85+
````
86+
87+
</Tabs.Tab>
88+
</Tabs>
5489
5590
If you run this with:
5691

0 commit comments

Comments
 (0)