Skip to content

Commit 30ec30e

Browse files
Ardeshir81IvanGoncharov
authored andcommitted
docs: follow express' best practice (#2252)
1 parent 5b88392 commit 30ec30e

6 files changed

+21
-14
lines changed

docs/Guides-ConstructingTypes.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ app.use(
5555
graphiql: true,
5656
}),
5757
);
58-
app.listen(4000);
59-
console.log('Running a GraphQL API server at localhost:4000/graphql');
58+
app.listen(4000, () => {
59+
console.log('Running a GraphQL API server at localhost:4000/graphql');
60+
});
6061
```
6162

6263
We can implement this same API without using GraphQL schema language:
@@ -114,8 +115,9 @@ app.use(
114115
graphiql: true,
115116
}),
116117
);
117-
app.listen(4000);
118-
console.log('Running a GraphQL API server at localhost:4000/graphql');
118+
app.listen(4000, () => {
119+
console.log('Running a GraphQL API server at localhost:4000/graphql');
120+
});
119121
```
120122

121123
When we use this method of creating the API, the root level resolvers are implemented on the `Query` and `Mutation` types rather than on a `root` object.

docs/Tutorial-Authentication.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ app.use(
4545
graphiql: true,
4646
}),
4747
);
48-
app.listen(4000);
49-
console.log('Running a GraphQL API server at localhost:4000/graphql');
48+
app.listen(4000, () => {
49+
console.log('Running a GraphQL API server at localhost:4000/graphql');
50+
});
5051
```
5152

5253
In a REST API, authentication is often handled with a header, that contains an auth token which proves what user is making this request. Express middleware processes these headers and puts authentication data on the Express `request` object. Some middleware modules that handle authentication like this are [Passport](http://passportjs.org/), [express-jwt](https://github.com/auth0/express-jwt), and [express-session](https://github.com/expressjs/session). Each of these modules works with `express-graphql`.

docs/Tutorial-BasicTypes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ app.use(
5252
graphiql: true,
5353
}),
5454
);
55-
app.listen(4000);
56-
console.log('Running a GraphQL API server at localhost:4000/graphql');
55+
app.listen(4000, () => {
56+
console.log('Running a GraphQL API server at localhost:4000/graphql');
57+
});
5758
```
5859

5960
If you run this code with `node server.js` and browse to http://localhost:4000/graphql you can try out these APIs.

docs/Tutorial-ExpressGraphQL.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ app.use(
4343
graphiql: true,
4444
}),
4545
);
46-
app.listen(4000);
47-
console.log('Running a GraphQL API server at localhost:4000/graphql');
46+
app.listen(4000, () => {
47+
console.log('Running a GraphQL API server at localhost:4000/graphql');
48+
});
4849
```
4950

5051
You can run this GraphQL server with:

docs/Tutorial-ObjectTypes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ app.use(
125125
graphiql: true,
126126
}),
127127
);
128-
app.listen(4000);
129-
console.log('Running a GraphQL API server at localhost:4000/graphql');
128+
app.listen(4000, () => {
129+
console.log('Running a GraphQL API server at localhost:4000/graphql');
130+
});
130131
```
131132

132133
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:

docs/Tutorial-PassingArguments.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ app.use(
8888
graphiql: true,
8989
}),
9090
);
91-
app.listen(4000);
92-
console.log('Running a GraphQL API server at localhost:4000/graphql');
91+
app.listen(4000, () => {
92+
console.log('Running a GraphQL API server at localhost:4000/graphql');
93+
});
9394
```
9495

9596
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:

0 commit comments

Comments
 (0)