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.

Thoughts on resolver forwarding

See original GitHub issue

Based on recent feedback, I’d like to kickstart an open discussion about the state of resolver forwarding and potential improvements.

forwardTo is a great convenience function:

const { forwardTo } = require('prisma-binding')

const Query = {
  posts: forwardTo('db'),
}

Here, we forward the posts query from our GraphQL server to a Prisma API. However, as soon as we want to modify the behaviour by, say, checking authentication before resolving, we have to fall back to the full ctx.db.query call:

const Query = {
   posts(parent, { where, skip, last, first }, ctx, info) {
    await checkAuth()
    return ctx.db.query.posts({ where, skip, last, first }, info)
  },
}

The best way to tackle this at the moment is to write a little convenience wrapper to check authentication like so:

const Query = {
   posts: checkAuth(forwardTo('db'))
}

Can you come up with other scenarios where resolver forwarding falls short, and approaches to improve the entire experience surrounding resolver forwarding?

#37 is a great idea in that direction, but I’m sure there are more great approaches to be found 🙂

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:24 (8 by maintainers)

github_iconTop GitHub Comments

12reactions
schicklingcommented, Dec 3, 2018

Update: We’re currently working on a new kind of GraphQL server framework which doesn’t require you duplicate your schema/resolver code while still making it easy to adjust/evolve your schema in an easy and (type-)safe way. (The best part: you won’t have to think about schema delegation or mess with the info object which is quite difficult to wrap your head around for newcomers.)

5reactions
lastmjscommented, Mar 13, 2018

This blog post offers potential simple solutions to these issues: https://medium.com/@lastmjs/advanced-graphql-directive-permissions-with-prisma-fdee6f846044

It shows a simple way to automatically expose all generated queries and mutations, and to easily combine those with your own custom schema and resolvers. Copying schema information is kept to a minimum. Permissions are handled elegantly through custom directives. Let me know if you have any questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DNS forwarder vs DNS resolver - Server Fault
A DNS forwarder will forward requests to another DNS resolver, and if it gets a result it will store this in a cache...
Read more >
What is the difference between a DNS resolver and a ... - Quora
A DNS “Forwarder” is a DNS server being USED by another DNS server to assist in resolving DNS queries.
Read more >
Managing forwarding rules - Amazon Route 53
If you want Resolver to forward queries for specified domain names to your network, you create one forwarding rule for each domain name...
Read more >
Forwarding — Knot Resolver 5.5.3 documentation
Forwarding configuration instructs resolver to forward cache-miss queries from clients to manually specified DNS resolvers (upstream servers).
Read more >
Difference between DNS Resolver and DNS Forwarder
Forwarder just forwards you question somewhere.. Be it just another forwarder or an actual resolver. But at some point a resolver has to...
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