Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't handle mixed query #109

Closed
roytan883 opened this issue Aug 1, 2018 · 5 comments
Closed

Can't handle mixed query #109

roytan883 opened this issue Aug 1, 2018 · 5 comments

Comments

@roytan883
Copy link

code like this:

const isAuthenticated = rule()(async (parent, args, ctx, info) => {
  console.log("call isAuthenticated args = ", args)
  return true
})
const permissions = shield({
  Query: {
    feed: isAuthenticated,
    post: isAuthenticated,
  },
})

If the query like this, the isAuthenticated only be called once !!!

query{
  feed{
    id
    text
  }
  post(id:"cjk9uyalu00110803ow0wrxwm"){
    id
    title
  }
}
@maticzav
Copy link
Owner

maticzav commented Aug 1, 2018

Hey @roytan883 👋,

Could you explain what the expected behaviour was? This could significantly improve my understanding of your problem.

@roytan883
Copy link
Author

roytan883 commented Aug 1, 2018

if i change the auth function name, you should understand:

const canGetFeed = rule()(async (parent, args, ctx, info) => {
  console.log("call canGetFeed")
  return true
})
const canGetPost = rule()(async (parent, args, ctx, info) => {
  console.log("call canGetPost")
  return false
})
const permissions = shield({
  Query: {
    feed: canGetFeed,
    post: canGetPost,
  },
})

Expect feed and post use different auth function. But the result is ONLY canGetFeed was called when is query like this:

query{
  feed{
    id
    text
  }
  post(id:"cjk9uyalu00110803ow0wrxwm"){
    id
    title
  }
}

@maticzav
Copy link
Owner

maticzav commented Aug 1, 2018

Hmm, ok. That is indeed an interesting situation. Let me explain how shield works; by default, every function is contextually cached. This means that regardless of parent or arguments function result caches and will be reused wherever the same rule is applied in a particular call.

Could you provide the actual code that you are using? That would help a lot.

Besides that, I recommend you check out the cache section of README. Maybe this could solve your problem. Otherwise I’ll help you get through the issue differently.

https://github.com/maticzav/graphql-shield/blob/master/README.md#cache

@maticzav
Copy link
Owner

Hey @roytan883 have you made any progress on this? 🙂

@stale
Copy link

stale bot commented Sep 29, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 29, 2018
@stale stale bot closed this as completed Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants