Skip to content

Commit 35dd486

Browse files
nodkzSashko Stubailo
authored and
Sashko Stubailo
committed
Fix: RootValue is a subvalue of fourth argument in the resolver method (graphql#160)
1 parent 343b4a2 commit 35dd486

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

site/learn/BestPractice-Authorization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var postType = new GraphQLObjectType({
2020
fields: {
2121
body: {
2222
type: GraphQLString,
23-
resolve: (post, args, context, rootValue) => {
23+
resolve: (post, args, context, { rootValue }) => {
2424
// return the post body only if the user is the post's author
2525
if (context.user && (context.user.id === post.authorId)) {
2626
return post.body;
@@ -45,14 +45,14 @@ var postType = new GraphQLObjectType({
4545
fields: {
4646
body: {
4747
type: GraphQLString,
48-
resolve: (post, args, context, rootValue) => {
48+
resolve: (post, args, context, { rootValue }) => {
4949
return postRepository.getBody(context.user, post);
5050
}
5151
}
5252
}
5353
});
5454
```
5555

56-
In the example above, we see that the business logic layer requires the caller to provide a user object. If you are using GraphQL.js, the User object should be populated on the `context` or `rootValue` arguments of the resolver.
56+
In the example above, we see that the business logic layer requires the caller to provide a user object. If you are using GraphQL.js, the User object should be populated on the `context` argument or `rootValue` in fourth argument of the resolver.
5757

5858
We recommend passing a fully-hydrated User object instead of an opaque token or API key to your business logic layer. This way, we can handle the distinct concerns of [authentication](/graphql-js/authentication-and-express-middleware/) and authorization in different stages of the request processing pipeline.

0 commit comments

Comments
 (0)