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.

Parent is undefined

See original GitHub issue

I’m following the examples for setting up with Prisma (using the Prisma graphql-authentication example) and everything is working great except when I try to use parent in a rule to establish user ownership.

const isOwner = rule()(async (parent, args, ctx, info) => {
  // Here, ctx contains my proper user object but parent is always undefined
  // without this permission, the yoga resolves the mutation just fine and the updated post is returned
  return ctx.user.items.some(id => id === parent.id)
})

const permissions = shield({
  Mutation: {
    updatePost: or(isAdmin, and(isOwner, isEditor))
  },
})

What I see is that the isOwner rule is being called before my updatePost resolver. Is this the intended behavior? Kinda makes sense not to hit the database if not authorized but then I have no chance to check the ownership of the post.

Does anyone know how parent is supposed to be populated? @maticzav explains nicely in https://github.com/prismagraphql/graphql-middleware/issues/19 that parent is the “result of the previous function. GraphQL works recursively by calling successive types determined by the schema. It starts off with undefined and continues execution down the chain forwarding the result of the previous resolver to the new one.” Ok. But my resolver is never called. What am I doing wrong?

Thanks so much!!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
nolandgcommented, Aug 15, 2018

Nevermind, I just read through all the source of shield and middlewares and I think I have a much better understanding now.

0reactions
maticzavcommented, Jan 21, 2019

Hey @nolandg @kitze 👋,

Have you heard of $exists method in Prisma? Its idea stems from a legacy Graphcool permission system where you could, using GraphQL queries, define permissions for your system. graphql-shield is designed especially with that in mind. This way, it doesn’t seem like you are fetching the same data twice. Additionally, I believe it is worth mentioning that prisma-binding, and prisma-client I believe as well, both feature a minor implementation of caching. Furthermore, graphql-shield also prevents duplication of requests by caching the result of a rule depending on the cache option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript returns undefined for parent and children element
I am trying to select the parent element of a clicked button, and find the child elements text of that parent element however...
Read more >
Undefined parent element - The W3C Markup Validation Service
Message. Undefined parent element: child ... If it is an undefined root element, then the document you are trying to validate is not...
Read more >
Passing value from parent to child lwc showing undefined
Passing value from parent to child lwc showing undefined · What is the context of how recordId is populated on the parent? ·...
Read more >
TypeError: Cannot read property 'parent' of undefined - Reddit
The error message means that some code tried to access thing.parent where thing happened to have the value undefined rather than some object....
Read more >
TypeError: parent is undefined · Issue #165 - GitHub
I'm having an issue I can't solve with the update prototype method. var filters = [ {title:'Volts', options:'ff'}, {title:'Type', ...
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