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
As written in the docs, a GraphQL::Function is a reusable container for field logic. However, extended Field DSL (specified using GraphQL::Field.accepts_definitions(...)) is not available within Functions.
Example
# Extend the Field DSL to accept :custom_metadata_keyGraphQL::Field.accepts_definitions(custom_metadata_key: GraphQL::Define.assign_metadata_key(:custom_metadata_key))
# This worksfield:myFielddocustom_metadata_key'test'end
# This does not workclassMyFunction < GraphQL::Functioncustom_metadata_key: 'test'endfield:myField,function: MyFunction.new
The problem is that GraphQL::Function is quite different from GraphQL::Field, GraphQL::ObjectType, etc, in that they are not defined (and therefore does not include the GraphQL::Define::InstanceDefinable module) and are instead subclassed.
Proposed Solutions
(Workaround) Define a class method within the Function.
Hook into Field.accepts_definitions to automatically define_singleton_method on GraphQL::Function.
(Ideal) Wait for Object-oriented schema definition #820 - perhaps we won't need Functions if we can simply inherit from GraphQL::Field to define reusable fields.
The text was updated successfully, but these errors were encountered:
As written in the docs, a
GraphQL::Function
is a reusable container for field logic. However, extended Field DSL (specified usingGraphQL::Field.accepts_definitions(...)
) is not available within Functions.Example
The problem is that
GraphQL::Function
is quite different fromGraphQL::Field
,GraphQL::ObjectType
, etc, in that they are not defined (and therefore does not include theGraphQL::Define::InstanceDefinable
module) and are instead subclassed.Proposed Solutions
Field.accepts_definitions
to automaticallydefine_singleton_method
onGraphQL::Function
.GraphQL::Field
to define reusable fields.The text was updated successfully, but these errors were encountered: