You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a field that is resolved lazily, e.g. using a GraphQL::Batch::Loader, and that field is selected in a query using a directive which applies to the field, the field will be resolved outside of the directive's scope (outside of the yield of the directive's resolve).
Say you're using a gem with a class method that's given a block and that method sets/reverts a class variable before/after the block is called. Then you write a directive that passes resolve's block into that gem's class method as its block. Given a lazy field that uses the class variable, that field will be resolved using the "after" value instead of the "during" value.
Versions
graphql version: 2.3.7 rails (or other framework): N/A
other applicable versions (graphql-batch, etc): graphql-batch 0.6.0
Run the query above using the provided schema and classes
Expected behavior
Both value and lazyValue resolve to red
Actual behavior
lazyValue resolves to nil because it's outside of the withAttribute directive scope when it gets resolved and so Attributed.with_attributed has reverted to its previous attr value.
The text was updated successfully, but these errors were encountered:
(At first, I thought putting GraphQL::Batch.batch { ... } inside def self.resolve would fix this problem, but it doesn't, because of that problem.)
And it won't be as easy as "just moving it up" to a higher spot in the call stack because of how GraphQL-Ruby does multiplexing. Given two queries like this:
We'd expect the first lazyValue to be run inside @withAttribute, but the second lazyValuenot to have @withAttribute. But GraphQL-Ruby can't make that guarantee because it runs all lazy values inside the same pool.
It might be possible to split them out -- detect queries which have directives and run them separately. That's the technique GraphQL-Ruby uses for fields and fragments, but there isn't already a place to do it for queries.)
I'll keep this open while I'm thinking it over and follow up here when I have anything more to report.
Describe the bug
If you have a field that is resolved lazily, e.g. using a
GraphQL::Batch::Loader
, and that field is selected in a query using a directive which applies to the field, the field will be resolved outside of the directive's scope (outside of theyield
of the directive'sresolve
).Say you're using a gem with a class method that's given a block and that method sets/reverts a class variable before/after the block is called. Then you write a directive that passes
resolve
's block into that gem's class method as its block. Given a lazy field that uses the class variable, that field will be resolved using the "after" value instead of the "during" value.Versions
graphql
version: 2.3.7rails
(or other framework): N/Aother applicable versions (
graphql-batch
, etc):graphql-batch
0.6.0GraphQL schema
GraphQL query
Steps to reproduce
Run the query above using the provided schema and classes
Expected behavior
Both
value
andlazyValue
resolve tored
Actual behavior
lazyValue
resolves to nil because it's outside of thewithAttribute
directive scope when it gets resolved and soAttributed.with_attributed
has reverted to its previousattr
value.The text was updated successfully, but these errors were encountered: