Skip to content

Commit bc93642

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

File tree

1 file changed

+64
-27
lines changed

1 file changed

+64
-27
lines changed

website/pages/index.mdx

Lines changed: 64 additions & 27 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,32 +27,67 @@ 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-
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
46-
graphql({
47-
schema,
48-
source: '{ hello }',
49-
rootValue,
50-
}).then((response) => {
51-
console.log(response);
52-
});
53-
```
30+
<Tabs items={['Template', 'Classes']}>
31+
<Tabs.Tab>
32+
```javascript
33+
const { graphql, buildSchema } = require('graphql');
34+
35+
// Construct a schema, using GraphQL schema language
36+
const schema = buildSchema(`
37+
type Query {
38+
hello: String
39+
}
40+
`);
41+
42+
// The rootValue provides a resolver function for each API endpoint
43+
const rootValue = {
44+
hello() {
45+
return 'Hello world!';
46+
},
47+
};
48+
49+
// Run the GraphQL query '{ hello }' and print out the response
50+
graphql({
51+
schema,
52+
source: '{ hello }',
53+
rootValue,
54+
}).then((response) => {
55+
console.log(response);
56+
});
57+
```
58+
</Tabs.Tab>
59+
<Tabs.Tab>
60+
```javascript
61+
const { graphql, buildSchema } = require('graphql');
62+
63+
// Construct a schema
64+
const schema = new GraphQLSchema({
65+
query: new GraphQLObjectType({
66+
name: 'Query',
67+
fields: {
68+
hello: { type: GraphQLString },
69+
},
70+
}),
71+
});
72+
73+
// The rootValue provides a resolver function for each API endpoint
74+
const rootValue = {
75+
hello() {
76+
return 'Hello world!';
77+
},
78+
};
79+
80+
// Run the GraphQL query '{ hello }' and print out the response
81+
graphql({
82+
schema,
83+
source: '{ hello }',
84+
rootValue,
85+
}).then((response) => {
86+
console.log(response);
87+
});
88+
```
89+
</Tabs.Tab>
90+
</Tabs>
5491

5592
If you run this with:
5693

0 commit comments

Comments
 (0)