Skip to content

Commit e9d7fc1

Browse files
docs: correctly tag code samples (#2256)
1 parent da64116 commit e9d7fc1

10 files changed

+32
-35
lines changed

docs/APIReference-Language.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ visit(ast, {
256256
// leave the "Kind" node
257257
}
258258
}
259-
})
259+
});
260260
```
261261
262262
3. Generic visitors that trigger upon entering and leaving any node.

docs/Guides-ConstructingTypes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ When you are using the `GraphQLSchema` constructor to create a schema, instead o
1212

1313
For example, let's say we are building a simple API that lets you fetch user data for a few hardcoded users based on an id. Using `buildSchema` we could write a server with:
1414

15-
```javascript
15+
```js
1616
var express = require('express');
1717
var graphqlHTTP = require('express-graphql');
1818
var { buildSchema } = require('graphql');
@@ -62,7 +62,7 @@ app.listen(4000, () => {
6262

6363
We can implement this same API without using GraphQL schema language:
6464

65-
```javascript
65+
```js
6666
var express = require('express');
6767
var graphqlHTTP = require('express-graphql');
6868
var graphql = require('graphql');

docs/Tutorial-Authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To use middleware with a GraphQL resolver, just use the middleware like you woul
1313

1414
For example, let's say we wanted our server to log the IP address of every request, and we also want to write an API that returns the IP address of the caller. We can do the former with middleware, and the latter by accessing the `request` object in a resolver. Here's server code that implements this:
1515

16-
```javascript
16+
```js
1717
var express = require('express');
1818
var graphqlHTTP = require('express-graphql');
1919
var { buildSchema } = require('graphql');

docs/Tutorial-BasicTypes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To use a list type, surround the type in square brackets, so `[Int]` is a list o
1616

1717
Each of these types maps straightforwardly to JavaScript, so you can just return plain old JavaScript objects in APIs that return these types. Here's an example that shows how to use some of these basic types:
1818

19-
```javascript
19+
```js
2020
var express = require('express');
2121
var graphqlHTTP = require('express-graphql');
2222
var { buildSchema } = require('graphql');

docs/Tutorial-ExpressGraphQL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install express express-graphql graphql --save
1515

1616
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 `express-graphql` library to mount a GraphQL API server on the “/graphql” HTTP endpoint:
1717

18-
```javascript
18+
```js
1919
var express = require('express');
2020
var graphqlHTTP = require('express-graphql');
2121
var { buildSchema } = require('graphql');

docs/Tutorial-GettingStarted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install graphql --save
2222

2323
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`:
2424

25-
```javascript
25+
```js
2626
var { graphql, buildSchema } = require('graphql');
2727

2828
// Construct a schema, using GraphQL schema language
@@ -53,7 +53,7 @@ node server.js
5353

5454
You should see the GraphQL response printed out:
5555

56-
```javascript
56+
```js
5757
{
5858
data: {
5959
hello: 'Hello world!';

docs/Tutorial-GraphQLClients.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ http://localhost:4000/graphql
1919

2020
You should see the output returned as JSON:
2121

22-
```bash
22+
```
2323
{"data":{"hello":"Hello world!"}}
2424
```
2525

2626
If you prefer to use a graphical user interface to send a test query, you can use clients such as [GraphiQL](https://github.com/graphql/graphiql) and [Insomnia](https://github.com/getinsomnia/insomnia).
2727

2828
It's also simple to send GraphQL from the browser. Open up http://localhost:4000, open a developer console, and paste in:
2929

30-
```javascript
30+
```js
3131
fetch('/graphql', {
3232
method: 'POST',
3333
headers: {
@@ -50,15 +50,15 @@ In this example, the query was just a hardcoded string. As your application beco
5050

5151
For example, let's say you're running the example server from [Passing Arguments](/graphql-js/passing-arguments/) that has a schema of
5252

53-
```javascript
53+
```graphql
5454
type Query {
5555
rollDice(numDice: Int!, numSides: Int): [Int]
5656
}
5757
```
5858

5959
You could access this from JavaScript with the code:
6060

61-
```javascript
61+
```js
6262
var dice = 3;
6363
var sides = 6;
6464
var query = `query RollDice($dice: Int!, $sides: Int) {

docs/Tutorial-Mutations.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you have an API endpoint that alters data, like inserting data into a databas
1010

1111
Let's say we have a “message of the day” server, where anyone can update the message of the day, and anyone can read the current one. The GraphQL schema for this is simply:
1212

13-
```javascript
13+
```graphql
1414
type Mutation {
1515
setMessage(message: String): String
1616
}
@@ -24,7 +24,7 @@ It's often convenient to have a mutation that maps to a database create or updat
2424

2525
Both mutations and queries can be handled by root resolvers, so the root that implements this schema can simply be:
2626

27-
```javascript
27+
```js
2828
var fakeDatabase = {};
2929
var root = {
3030
setMessage: function({ message }) {
@@ -41,7 +41,7 @@ You don't need anything more than this to implement mutations. But in many cases
4141

4242
For example, instead of a single message of the day, let's say we have many messages, indexed in a database by the `id` field, and each message has both a `content` string and an `author` string. We want a mutation API both for creating a new message and for updating an old message. We could use the schema:
4343

44-
```javascript
44+
```graphql
4545
input MessageInput {
4646
content: String
4747
author: String
@@ -71,7 +71,7 @@ Naming input types with `Input` on the end is a useful convention, because you w
7171

7272
Here's some runnable code that implements this schema, keeping the data in memory:
7373

74-
```javascript
74+
```js
7575
var express = require('express');
7676
var graphqlHTTP = require('express-graphql');
7777
var { buildSchema } = require('graphql');
@@ -153,20 +153,17 @@ app.listen(4000, () => {
153153

154154
To call a mutation, you must use the keyword `mutation` before your GraphQL query. To pass an input type, provide the data written as if it's a JSON object. For example, with the server defined above, you can create a new message and return the `id` of the new message with this operation:
155155

156-
```javascript
156+
```graphql
157157
mutation {
158-
createMessage(input: {
159-
author: "andy",
160-
content: "hope is a good thing",
161-
}) {
158+
createMessage(input: { author: "andy", content: "hope is a good thing" }) {
162159
id
163160
}
164161
}
165162
```
166163

167164
You can use variables to simplify mutation client logic just like you can with queries. For example, some JavaScript code that calls the server to execute this mutation is:
168165

169-
```javascript
166+
```js
170167
var author = 'andy';
171168
var content = 'hope is a good thing';
172169
var query = `mutation CreateMessage($input: MessageInput) {

docs/Tutorial-ObjectTypes.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ In many cases, you don't want to return a number or a string from an API. You wa
1010

1111
In GraphQL schema language, the way you define a new object type is the same way we have been defining the `Query` type in our examples. Each object can have fields that return a particular type, and methods that take arguments. For example, in the [Passing Arguments](/graphql-js/passing-arguments/) documentation, we had a method to roll some random dice:
1212

13-
```javascript
13+
```graphql
1414
type Query {
1515
rollDice(numDice: Int!, numSides: Int): [Int]
1616
}
1717
```
1818

1919
If we wanted to have more and more methods based on a random die over time, we could implement this with a `RandomDie` object type instead.
2020

21-
```javascript
21+
```graphql
2222
type RandomDie {
2323
roll(numRolls: Int!): [Int]
2424
}
@@ -30,7 +30,7 @@ type Query {
3030

3131
Instead of a root-level resolver for the `RandomDie` type, we can instead use an ES6 class, where the resolvers are instance methods. This code shows how the `RandomDie` schema above can be implemented:
3232

33-
```javascript
33+
```js
3434
class RandomDie {
3535
constructor(numSides) {
3636
this.numSides = numSides;
@@ -58,7 +58,7 @@ var root = {
5858

5959
For fields that don't use any arguments, you can use either properties on the object or instance methods. So for the example code above, both `numSides` and `rollOnce` can actually be used to implement GraphQL fields, so that code also implements the schema of:
6060

61-
```javascript
61+
```graphql
6262
type RandomDie {
6363
numSides: Int!
6464
rollOnce: Int!
@@ -72,7 +72,7 @@ type Query {
7272

7373
Putting this all together, here is some sample code that runs a server with this GraphQL API:
7474

75-
```javascript
75+
```js
7676
var express = require('express');
7777
var graphqlHTTP = require('express-graphql');
7878
var { buildSchema } = require('graphql');
@@ -132,7 +132,7 @@ app.listen(4000, () => {
132132

133133
When you issue a GraphQL query against an API that returns object types, you can call multiple methods on the object at once by nesting the GraphQL field names. For example, if you wanted to call both `rollOnce` to roll a die once, and `roll` to roll a die three times, you could do it with this query:
134134

135-
```javascript
135+
```graphql
136136
{
137137
getDie(numSides: 6) {
138138
rollOnce

docs/Tutorial-PassingArguments.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ next: /graphql-js/object-types/
88

99
Just like a REST API, it's common to pass arguments to an endpoint in a GraphQL API. By defining the arguments in the schema language, typechecking happens automatically. Each argument must be named and have a type. For example, in the [Basic Types documentation](/graphql-js/basic-types/) we had an endpoint called `rollThreeDice`:
1010

11-
```javascript
11+
```graphql
1212
type Query {
1313
rollThreeDice: [Int]
1414
}
1515
```
1616

1717
Instead of hardcodingthree”, we might want a more general function that rolls `numDice` dice, each of which have `numSides` sides. We can add arguments to the GraphQL schema language like this:
1818

19-
```javascript
19+
```graphql
2020
type Query {
2121
rollDice(numDice: Int!, numSides: Int): [Int]
2222
}
@@ -26,7 +26,7 @@ The exclamation point in `Int!` indicates that `numDice` can't be null, which me
2626

2727
So far, our resolver functions took no arguments. When a resolver takes arguments, they are passed as one “args” object, as the first argument to the function. So rollDice could be implemented as:
2828

29-
```javascript
29+
```js
3030
var root = {
3131
rollDice: function(args) {
3232
var output = [];
@@ -40,7 +40,7 @@ var root = {
4040

4141
It's convenient to use [ES6 destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) for these parameters, since you know what format they will be. So we can also write `rollDice` as
4242

43-
```javascript
43+
```js
4444
var root = {
4545
rollDice: function({ numDice, numSides }) {
4646
var output = [];
@@ -56,7 +56,7 @@ If you're familiar with destructuring, this is a bit nicer because the line of c
5656

5757
The entire code for a server that hosts this `rollDice` API is:
5858

59-
```javascript
59+
```js
6060
var express = require('express');
6161
var graphqlHTTP = require('express-graphql');
6262
var { buildSchema } = require('graphql');
@@ -95,7 +95,7 @@ app.listen(4000, () => {
9595

9696
When you call this API, you have to pass each argument by name. So for the server above, you could issue this GraphQL query to roll three six-sided dice:
9797

98-
```javascript
98+
```graphql
9999
{
100100
rollDice(numDice: 3, numSides: 6)
101101
}
@@ -107,7 +107,7 @@ When you're passing arguments in code, it's generally better to avoid constructi
107107

108108
For example, some JavaScript code that calls our server above is:
109109

110-
```javascript
110+
```js
111111
var dice = 3;
112112
var sides = 6;
113113
var query = `query RollDice($dice: Int!, $sides: Int) {

0 commit comments

Comments
 (0)