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.

GraphQL Shield response 2times slower on response with large list

See original GitHub issue

Bug report

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

Describe the bug

When i return a large document with a array (1000+ elements) it increases response times with almost factor 2 with GraphQL running. When i remove GraphQL shield from the ApplyMiddleware the response time is greatly reduced.

To Reproduce

Have a object with a large list of around 1Mb. Return it with GraphQL shield enabled and disabled and see the differences

Expected behavior

I expect milli second slowdown because of rule check, it looks like every element of the schema is checked. (if so can i disable this is certain types?)

Reproduction

A codesandbox can be found here: https://codesandbox.io/s/gracious-dust-55156?file=/index.js On code line 77 comment out “permissions” use the graphQL playground to see the differences in speed.

use the following query:

{ hello { id start end numbera mainitems{ numbera floata floatb floatc floatd floate items { floataa floatbb numberaa floatcc numberbb timestamp subobj{ floataaa floatbbb } } } } }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
mindnektarcommented, Sep 2, 2021

If anyone’s still bothered by this, I’ve figured out a way around the problem.

According to the documentation, there are three values you can specify for the caching option: no_cache, contextual and strict. It is suggested that you use the strict option if the resolution of your rule depends on the parent or args parameter. The problem is that when using strict, the cache key is a hash generated from the entire parent and args objects. This is both rather slow for large objects and data sets and too strict, because in my case at least, there are no identical combinations of parent and args, even though the same parent might in fact be referenced, I just define “same” differently.

It turns out there is a fourth caching option: You can pass a function that returns the cache key the rule should use. In my case, I could simply use cache: (parent) => parent.id and that was that. All the permissions I set still work and all my requests are 2-5 times faster.

I hope I could save someone some headache with this.

1reaction
tanahel-udemcommented, Feb 21, 2022

If anyone is still experiencing this problem, I found a hacky solution.

I’ve found that my performance issue was that graph QL shield wrap even defaults resolvers in async functions to handle permissions and errors. In my case since I do not need the error handling and my fallback rule is “allow”. I found that keeping only the part of the shield middleware I explicitly define does is faster and still validates the rules I need.

Here is how I removed them: https://codesandbox.io/s/dreamy-brahmagupta-vr8ysw?file=/index.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Shield response 2times slower on ... - GitHub
When i return a large document with a array (1000+ elements) it increases response times with almost factor 2 with GraphQL running. When...
Read more >
Troubleshooting – GraphQL Shield
This is a list of frequently asked questions and their short explanations. When a single field is "Not Authorised!" the entire parent object ......
Read more >
Front-End Performance Checklist 2021 (PDF, Apple Pages ...
Measures the loading of a page, and reports the render time of the largest image or text block that's visible within the viewport....
Read more >
Untitled
Major sources of communicable diseases, Samsung cell 18650? ... Buddha bar paris price list, Cnpf foret, Guwahati to tawang route map, Dpph assay...
Read more >
Untitled
If-275 manual, Kalinka song mp3, Ssc gd answer key download 2012, ... Kaffee-whisky-torte, Top fuel slow motion, How long to lose one percent...
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