Skip to content

Commit 8e68160

Browse files
authored
Merge pull request graphql#636 from dcavalcante/source
Changed GraphQL.js Tutorial to arrow functions
2 parents 81e28d2 + 6790848 commit 8e68160

5 files changed

+13
-13
lines changed

site/graphql-js/Guides-ConstructingTypes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var fakeDatabase = {
4141
};
4242

4343
var root = {
44-
user: function ({id}) {
44+
user: ({id}) => {
4545
return fakeDatabase[id];
4646
}
4747
};
@@ -94,7 +94,7 @@ var queryType = new graphql.GraphQLObjectType({
9494
args: {
9595
id: { type: graphql.GraphQLString }
9696
},
97-
resolve: function (_, {id}) {
97+
resolve: (_, {id}) => {
9898
return fakeDatabase[id];
9999
}
100100
}

site/graphql-js/Tutorial-Authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var schema = buildSchema(`
2424
}
2525
`);
2626

27-
function loggingMiddleware(req, res, next) {
27+
const loggingMiddleware = (req, res, next) => {
2828
console.log('ip:', req.ip);
2929
next();
3030
}

site/graphql-js/Tutorial-Mutations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Both mutations and queries can be handled by root resolvers, so the root that im
2727
```javascript
2828
var fakeDatabase = {};
2929
var root = {
30-
setMessage: function ({message}) {
30+
setMessage: ({message}) => {
3131
fakeDatabase.message = message;
3232
return message;
3333
},
34-
getMessage: function () {
34+
getMessage: () => {
3535
return fakeDatabase.message;
3636
}
3737
};
@@ -112,20 +112,20 @@ class Message {
112112
var fakeDatabase = {};
113113

114114
var root = {
115-
getMessage: function ({id}) {
115+
getMessage: ({id}) => {
116116
if (!fakeDatabase[id]) {
117117
throw new Error('no message exists with id ' + id);
118118
}
119119
return new Message(id, fakeDatabase[id]);
120120
},
121-
createMessage: function ({input}) {
121+
createMessage: ({input}) => {
122122
// Create a random id for our "database".
123123
var id = require('crypto').randomBytes(10).toString('hex');
124124

125125
fakeDatabase[id] = input;
126126
return new Message(id, input);
127127
},
128-
updateMessage: function ({id, input}) {
128+
updateMessage: ({id, input}) => {
129129
if (!fakeDatabase[id]) {
130130
throw new Error('no message exists with id ' + id);
131131
}

site/graphql-js/Tutorial-ObjectTypes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RandomDie {
5050
}
5151

5252
var root = {
53-
getDie: function ({numSides}) {
53+
getDie: ({numSides}) => {
5454
return new RandomDie(numSides || 6);
5555
}
5656
}
@@ -111,7 +111,7 @@ class RandomDie {
111111

112112
// The root provides the top-level API endpoints
113113
var root = {
114-
getDie: function ({numSides}) {
114+
getDie: ({numSides}) => {
115115
return new RandomDie(numSides || 6);
116116
}
117117
}

site/graphql-js/Tutorial-PassingArguments.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ So far, our resolver functions took no arguments. When a resolver takes argument
2828

2929
```javascript
3030
var root = {
31-
rollDice: function (args) {
31+
rollDice: (args) => {
3232
var output = [];
3333
for (var i = 0; i < args.numDice; i++) {
3434
output.push(1 + Math.floor(Math.random() * (args.numSides || 6)));
@@ -42,7 +42,7 @@ It's convenient to use [ES6 destructuring assignment](https://developer.mozilla.
4242

4343
```javascript
4444
var root = {
45-
rollDice: function ({numDice, numSides}) {
45+
rollDice: ({numDice, numSides}) => {
4646
var output = [];
4747
for (var i = 0; i < numDice; i++) {
4848
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
@@ -70,7 +70,7 @@ var schema = buildSchema(`
7070

7171
// The root provides a resolver function for each API endpoint
7272
var root = {
73-
rollDice: function ({numDice, numSides}) {
73+
rollDice: ({numDice, numSides}) => {
7474
var output = [];
7575
for (var i = 0; i < numDice; i++) {
7676
output.push(1 + Math.floor(Math.random() * (numSides || 6)));

0 commit comments

Comments
 (0)