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.

Shield rules with cache: "strict" don't work on types.

See original GitHub issue

Bug report

  • [x ] I have checked other issues to make sure this is not a duplicate.

Describe the bug

When using shield rule on type with cache: "strict" authorization result is always “Not Authorized”

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

(Delete the filler code and replace it with your own)

  1. This is my GraphQL Schema.
type Query {
  clinics: [Clinic]!
}

type Clinic {
  id: ID!
  name: String!
}
  1. This is the invoked query
clinics {
  id
  name
}
  1. I use these permissions
const permissions = shield({
  Query: {
    clinics: allow,
  },
  Clinic: rule({ cache: 'strict' })(async (parent, args, ctx, info) => {
    return true;
  }),,
})
  1. All results are not authorized.

Expected behavior

Rule should be called once per “Type” and validate access to it.

Actual behaviour

Rule always return “Not authorized”

Additional

If this is wrong usage of rules then it should be somehow thrown as an error

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
todda00commented, Oct 25, 2019

I can’t seem to recreate this issue anymore either - I have set all my rules back from no_cache to strict which were strict previously. As we test the app I will let you know if anything pops up, but I can’t recreate it inside our app, or in the sandbox you provided.

1reaction
todda00commented, Oct 17, 2019

I have run into this issue, but specifically only when a parent is null and cache === “strict”. The rule does not even run at all. When debug=true, the following error is output:

Cannot read property '3' of undefined

stacktrace:

TypeError: Cannot read property '3' of undefined,
    at Object.get [as generationTime] ([redacted]/node_modules/bson/lib/bson/objectid.js:373:19),
    at [redacted]/node_modules/object-hash/index.js:246:33,
    at Array.forEach (<anonymous>),
    at Object._object ([redacted]/node_modules/object-hash/index.js:242:21),
    at Object.dispatch ([redacted]/node_modules/object-hash/index.js:185:30),
    at [redacted]/node_modules/object-hash/index.js:246:18,
    at Array.forEach (<anonymous>),
    at Object._object ([redacted]/node_modules/object-hash/index.js:242:21),
    at Object.dispatch ([redacted]/node_modules/object-hash/index.js:185:30),
    at [redacted]/node_modules/object-hash/index.js:246:18,
    at Array.forEach (<anonymous>),
    at Object._object ([redacted]/node_modules/object-hash/index.js:242:21),
    at Object.dispatch ([redacted]/node_modules/object-hash/index.js:185:30),
    at [redacted]/node_modules/object-hash/index.js:246:18,
    at Array.forEach (<anonymous>),
    at Object._object ([redacted]/node_modules/object-hash/index.js:242:21),
    at Object.dispatch ([redacted]/node_modules/object-hash/index.js:185:30),
    at hash ([redacted]/node_modules/object-hash/index.js:128:10),
    at Object.objectHash [as hashFunction] ([redacted]/node_modules/object-hash/index.js:33:10),
    at Rule.executeRule ([redacted]/node_modules/graphql-shield/src/rules.ts:162:33),
    at Rule.resolve ([redacted]/node_modules/graphql-shield/src/rules.ts:58:30),
    at middleware ([redacted]/node_modules/graphql-shield/src/generator.ts:67:30),
    at [redacted]/node_modules/graphql-middleware/src/applicator.ts:32:5,
    at field.resolve ([redacted]/node_modules/apollo-server-core/node_modules/graphql-extensions/src/index.ts:274:18),
    at resolveFieldValueOrError ([redacted]/node_modules/graphql/execution/execute.js:503:18),
    at resolveField ([redacted]/node_modules/graphql/execution/execute.js:470:16),
    at executeFields ([redacted]/node_modules/graphql/execution/execute.js:311:18),
    at collectAndExecuteSubfields ([redacted]/node_modules/graphql/execution/execute.js:747:10),
    at completeObjectValue ([redacted]/node_modules/graphql/execution/execute.js:737:10),
    at completeValue ([redacted]/node_modules/graphql/execution/execute.js:626:12),
    at [redacted]/node_modules/graphql/execution/execute.js:528:16,
    at process._tickCallback (internal/process/next_tick.js:68:7)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching - Akamai TechDocs
​Akamai​ servers don't cache objects when the no-store or no-cache directives are present in the. Cache-Control header, or when the private directive is...
Read more >
Cache Coherence - an overview | ScienceDirect Topics
Cache coherence is a concern in a multicore environment because of distributed L1 and L2 caches. Since each core has its own cache,...
Read more >
Configuring Caching and Compression - Barracuda Campus
Caching works well for responses containing static pages which remain unmodified over multiple requests. When response content is likely to ...
Read more >
Easy Cloudflare Tutorial (including Page Cache rules)
Improve your website's performance with this detailed Cloudflare tutorial. It includes optimized Page Rules and the correct Page Cache rule ...
Read more >
How to Cache Dynamic Content in WordPress - WP Rocket
In this article you'll learn what's dynamic content, how dynamic content caching works, its various benefits, and the multiple ways you can ...
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