Recommended way of passing information to the next resolver?
See original GitHub issueI’m wondering what’s the best approach to achieve the following behaviour:
1st resolver: Checks if user is authenticated 2nd resolver: Checks if user has permissions to edit the document. Since we already fetched the document in this step to check permissions, it would be nice to be able to pass the document to the next resolver. 3rd resolver: Query or make the changes to the document in question.
This is what my resolvers look like so far:
const isAuthenticatedResolver = createResolver((root, args, { user }) => {
if (!user) throw new UnauthenticatedError();
});
const isInOrganization = isAuthenticatedResolver.createResolver(
(root, { organizationId }, { user }) => {
return Organization.findOne({ _id: organizationId, owner: user.id })
.then(organization => {
if (!organization) throw new CustomError('Please check you have permission to access this organization');
// How do I pass organization to the next stage?
// I tried `return`ing organization at this point, but that resolves[?] the resolver and prevents
// the next one to be executed.
});
}
);
const RootResolver = {
getMembers: isInOrganization.createResolver(
(organization) => organization.getMembers()
)
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Resolvers - Apollo GraphQL Docs
Resolver functions are passed four arguments: parent , args , contextValue , and info (in that order). You can use any name for...
Read more >Avoid overfetching with properly designed GraphQL resolvers
GraphQL's biggest advantage over REST is that it solves the issue of overfetching data — so long as you have properly designed resolvers....
Read more >Resolver/Arguments.md at master - GitHub
Handling multiple arguments is done simply by passing a dictionary to Resolver. class ViewController: UIViewController, Resolving { lazy var viewModel: ...
Read more >How To Use Route Resolvers with Angular Router
There is another way to use what is known as a route resolver , which allows you to get data before navigating to...
Read more >Resolver mapping template overview - AWS AppSync
Resolvers are the connectors between GraphQL and a data source. ... of resolvers in AWS AppSync that leverage mapping templates in slightly different...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@thebigredgeek - Any feedback for this? It seems like a pretty important feature. Is context really the only way?
Closing this due to lack of activity