You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/graphql-js/authentication-and-express-middleware.mdx
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,41 +10,41 @@ To use middleware with a GraphQL resolver, just use the middleware like you woul
10
10
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:
11
11
12
12
```js
13
-
var express =require("express")
14
-
var { createHandler } =require("graphql-http/lib/use/express")
console.log("Running a GraphQL API server at localhost:4000/graphql")
45
+
);
46
+
app.listen(4000);
47
+
console.log("Running a GraphQL API server at localhost:4000/graphql");
48
48
```
49
49
50
50
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 `graphql-http`.
Copy file name to clipboardExpand all lines: src/pages/graphql-js/basic-types.mdx
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,42 +13,42 @@ To use a list type, surround the type in square brackets, so `[Int]` is a list o
13
13
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:
14
14
15
15
```js
16
-
var express =require("express")
17
-
var { createHandler } =require("graphql-http/lib/use/express")
Copy file name to clipboardExpand all lines: src/pages/graphql-js/constructing-types.mdx
+38-34Lines changed: 38 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,11 @@ When you are using the `GraphQLSchema` constructor to create a schema, instead o
9
9
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:
10
10
11
11
```js
12
-
var express =require("express")
13
-
var { createHandler } =require("graphql-http/lib/use/express")
console.log("Running a GraphQL API server at localhost:4000/graphql")
114
+
);
115
+
app.listen(4000);
116
+
console.log("Running a GraphQL API server at localhost:4000/graphql");
113
117
```
114
118
115
119
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.
0 commit comments