-
Notifications
You must be signed in to change notification settings - Fork 106
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
graphql-ruby 1.9 interpreter support #93
Comments
That's what came to mind for me too, the library requires the same thing for subscription root in the new runtime: |
Possibly the module could be included automatically, although perhaps that is too invasive. At least the field instrumentation is only needed for the mutation root object type.
Currently that works through overriding |
That subscription root example is a little different I think since it works via field extensions. The example I had above just overrides class BaseMutation < GraphQL::Schema::Mutation
include GraphQL::Batch::Mutation
end
class ProductCreate < BaseMutation
# etc
end |
That is just a less generic replacement for field instrumentation which relies on an external resolver to be used. As https://graphql-ruby.org/mutations/mutation_root.html says
so that could be a problem if the field isn't defined using a mutation class. |
That's a good point although I do wonder how much we should cater to that non-standard use case. I guess it depends what the alternatives look like. I guess it's not much different: module GraphQL::Batch::Mutation
def field(*args, extensions: [], **rest, &block)
extensions += [GraphQL::Batch::Mutation::Extension]
super(*args, extensions: extensions, **rest, &block)
end
class Extension < GraphQL::Schema::FieldExtension
def before_resolve(object:, arguments:, context:)
GraphQL::Batch::Executor.current.clear
yield(object, arguments, nil)
end
def after_resolve(object:, arguments:, context:, value:, memo:)
GraphQL::Batch::Executor.current.clear
value
end
end
end
class MutationRoot < BaseObject
extend GraphQL::Batch::Mutation
end @rmosolgo I'm a little hazy on extensions, but is that all that's needed? Or do we still need to explicitly call |
I'm pretty sure the result will be synced automatically. The reason why GraphQL::Batch::Setup does it explicitly is so that it can call |
What if the gem offered hooks around After a quick look at the gem I think the main issue is the lazy related methods only take a |
Personally, I'm interested in exploring this more. Historically GraphQL-Ruby has suffered from too much "do it however you want" and not enough, "this is how X is done". So in my opinion, supporting custom batching in I'm not sure how to do a completely agnostic approach. Lots of options and their shortcomings are discussed here. Even dynamically, you couldn't check Maybe you could do something like schema.mutation.fields.each { |name, f| f.extension(MutationBatching) } But some of |
I don't think we should actually worry that much about a mutation field coming from an interface. If there were a simple way to handle that, then it would be relevant though. If we want to be paranoid, then we could try to detect that happening and raise. I would be more concerned about fields defined directly on a mutation type seemingly like they work but actually having a subtle bug from this extension not applying to them. If we don't want to support that, then perhaps we could detect that as well and raise to make this clear. |
schema.mutation.fields.each { |name, f| f.extension(MutationBatching) } This seems like the best option so far since it works with the existing |
I took a try like that over at #99, feel free to use it as inspiration (or evidence to try another approach), or I'm happy to improve it according to your review! |
Fixed by #99 |
1.9 offers a new optional interpreter and AST-based analysis which has breaking changes. Field instrumentation won't be supported and graphql-batch uses it for mutations:
graphql-batch/lib/graphql/batch/setup.rb
Lines 12 to 25 in d1244b7
Ideally we'd support both and conditionally check the gem version. Here's one idea on how to support 1.9 borrowed from @rmosolgo :
We'll have to figure out a good way of hooking into
resolve_with_support
. I'm not sure it's possible without some manual intervention (including a module for example).The text was updated successfully, but these errors were encountered: