Skip to content

Commit 4666dc1

Browse files
soneymathewleebyron
authored andcommitted
Improve documention of resolve function - add info param (graphql#451)
1 parent 92c39cb commit 4666dc1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

site/learn/Learn-Execution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@ In this example, our Query type provides a field called `human` which accepts th
6060

6161
```js
6262
Query: {
63-
human(obj, args, context) {
63+
human(obj, args, context, info) {
6464
return context.db.loadHumanByID(args.id).then(
6565
userData => new Human(userData)
6666
)
6767
}
6868
}
6969
```
7070

71-
This example is written in JavaScript, however GraphQL servers can be built in [many different languages](/code/). A resolver function receives three arguments:
71+
This example is written in JavaScript, however GraphQL servers can be built in [many different languages](/code/). A resolver function receives four arguments:
7272

7373
- `obj` The previous object, which for a field on the root Query type is often not used.
7474
- `args` The arguments provided to the field in the GraphQL query.
7575
- `context` A value which is provided to every resolver and holds important contextual information like the currently logged in user, or access to a database.
76-
76+
- `info` A value which holds field-specific information relevant to the current query as well as the schema details, also [refer type GraphQLResolveInfo for more details](/graphql-js/type/#graphqlobjecttype).
7777

7878
## Asynchronous resolvers
7979

8080
Let's take a closer look at what's happening in this resolver function.
8181

8282
```js
83-
human(obj, args, context) {
83+
human(obj, args, context, info) {
8484
return context.db.loadHumanByID(args.id).then(
8585
userData => new Human(userData)
8686
)
@@ -98,7 +98,7 @@ Now that a `Human` object is available, GraphQL execution can continue with the
9898

9999
```js
100100
Human: {
101-
name(obj, args, context) {
101+
name(obj, args, context, info) {
102102
return obj.name
103103
}
104104
}
@@ -134,7 +134,7 @@ We've already seen a bit of what happens when a field returns a list of things w
134134

135135
```js
136136
Human: {
137-
starships(obj, args, context) {
137+
starships(obj, args, context, info) {
138138
return obj.starshipIDs.map(
139139
id => context.db.loadStarshipByID(id).then(
140140
shipData => new Starship(shipData)

0 commit comments

Comments
 (0)