question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recommended way of passing information to the next resolver?

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
joenot443commented, Feb 15, 2018

@thebigredgeek - Any feedback for this? It seems like a pretty important feature. Is context really the only way?

0reactions
thebigredgeekcommented, May 13, 2018

Closing this due to lack of activity

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found