It seems to work fine when the resolver returns a collection, and when a resolver returns a single object that is not cached. But, when there's a cache-hit, I always get this error:
E GraphqlController -- Failed to implement Post.id, tried:
- `Types::Post#id`, which did not exist
- `PostDecorator#id`, which did not exist
- Looking up hash key `:id` or `"id"` on `#<GraphQL::Execution::Interpreter::RawValue:0x00000001105e7980>`, but it wasn't a Hash
To implement this field, define one of the methods above (and check for typos)
12:45:58 E GraphqlController -- /Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/field.rb:848:in `block in public_send_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/field.rb:911:in `with_extensions'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/field.rb:803:in `public_send_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/field.rb:717:in `block in resolve'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema.rb:118:in `after_lazy'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/field.rb:715:in `resolve'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:511:in `block (4 levels) in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:81:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `block in call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-fragment_cache-1.11.0/lib/graphql/fragment_cache/schema/tracer.rb:12:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:67:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:510:in `block (3 levels) in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/query.rb:366:in `block in with_error_handling'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/errors.rb:107:in `with_error_handling'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/query.rb:365:in `with_error_handling'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:509:in `block (2 levels) in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:812:in `call_method_on_directives'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:506:in `block in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:915:in `after_lazy'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:440:in `evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:428:in `evaluate_selection'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:359:in `block (2 levels) in evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/dataloader/null_dataloader.rb:17:in `append_job'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:358:in `block in evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:357:in `each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:357:in `evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:739:in `block (3 levels) in continue_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:812:in `call_method_on_directives'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:738:in `block (2 levels) in continue_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:190:in `tap_or_each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:729:in `block in continue_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:915:in `after_lazy'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:715:in `continue_field'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:520:in `block (3 levels) in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:915:in `after_lazy'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:517:in `block (2 levels) in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:812:in `call_method_on_directives'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:506:in `block in evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:915:in `after_lazy'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:440:in `evaluate_selection_with_args'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:432:in `block in evaluate_selection'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/member/has_arguments.rb:204:in `block (3 levels) in coerce_arguments'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/dataloader/null_dataloader.rb:17:in `append_job'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/member/has_arguments.rb:185:in `block (2 levels) in coerce_arguments'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/member/has_arguments.rb:184:in `each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/member/has_arguments.rb:184:in `block in coerce_arguments'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema/member/has_arguments.rb:213:in `coerce_arguments'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/arguments_cache.rb:52:in `dataload_for'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:431:in `evaluate_selection'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:359:in `block (2 levels) in evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/dataloader/null_dataloader.rb:17:in `append_job'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:358:in `block in evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:357:in `each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:357:in `evaluate_selections'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:231:in `block (4 levels) in run_eager'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:812:in `call_method_on_directives'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:230:in `block (3 levels) in run_eager'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/dataloader/null_dataloader.rb:17:in `append_job'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:228:in `block (2 levels) in run_eager'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:190:in `tap_or_each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:219:in `block in run_eager'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:812:in `call_method_on_directives'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter/runtime.rb:210:in `run_eager'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter.rb:73:in `block in evaluate'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:81:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `block in call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-fragment_cache-1.11.0/lib/graphql/fragment_cache/schema/tracer.rb:12:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:67:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter.rb:72:in `evaluate'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/interpreter.rb:48:in `begin_query'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:85:in `begin_query'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:104:in `block (2 levels) in run_as_multiplex'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/dataloader/null_dataloader.rb:17:in `append_job'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:104:in `block in run_as_multiplex'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:103:in `each'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:103:in `each_with_index'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:103:in `run_as_multiplex'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:63:in `block (2 levels) in run_queries'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:211:in `block in instrument_and_analyze'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:29:in `block (2 levels) in apply_instrumenters'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:46:in `block (2 levels) in each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:46:in `block (2 levels) in each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:41:in `each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:45:in `block in each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:45:in `block in each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:72:in `call_hooks'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:190:in `instrument_and_analyze'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:62:in `block in run_queries'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:81:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `block in call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-fragment_cache-1.11.0/lib/graphql/fragment_cache/schema/tracer.rb:12:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:83:in `call_tracers'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/tracing.rb:67:in `trace'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:60:in `run_queries'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/execution/multiplex.rb:50:in `run_all'
/Users/victor/.rvm/gems/ruby-2.7.4/gems/graphql-1.13.10/lib/graphql/schema.rb:1767:in `multiplex'
/Users/victor/Development/project/app/controllers/graphql_controller.rb:49:in `create'
I can call .resolve
on this and get a Hash, but then some custom relationships that access object.comments
would fail as it's now a Hash, which means I probably need to Post.build(cache_fragment { }.resolve)
or something, but from what I understand this should not be needed.
For what it's worth, I have a custom field class that looks like:
module Types::Base
class Field < GraphQL::Schema::Field
argument_class Types::Base::Argument
# Pass `field ..., unauthorized: true` to allow public requests
def initialize(*args, unauthorized: false, **kwargs, &block)
@unauthorized = unauthorized
super(*args, **kwargs, &block)
end
# Only allow logged in users unless authorized: true
def authorized?(obj, args, ctx)
return true if @unauthorized
return false unless ctx[:current_user].present?
true
end
end
end
I have included it in my schema like so:
class ProjectSchema < GraphQL::Schema
use GraphQL::FragmentCache
use GraphQL::Subscriptions::ActionCableSubscriptions, serializer: Subscriptions::Serialize
mutation(Types::MutationType)
query(Types::QueryType)
subscription(Types::SubscriptionType)
use GraphQL::Decorate
and applied it to my base resolver:
module Resolvers
class Base < GraphQL::Schema::Resolver
argument_class Types::Base::Argument
include GraphQL::FragmentCache::ObjectHelpers
...
and to my base object:
module Types::Base
class Object < GraphQL::Schema::Object
include GraphQL::FragmentCache::Object
include GraphQL::Decorate::ObjectIntegration
field_class(Types::Base::Field)
edge_type_class(Types::Base::Edge)
connection_type_class(Types::Base::Connection)
end
end
What am I doing wrong here?
What am I doing wrong here?