module GraphQL::Schema::Member::AcceptsDefinition
Support for legacy `accepts_definitions` functions.
Keep the legacy handler hooked up. Class-based types and fields will call those legacy handlers during their `.to_graphql` methods.
This can help out while transitioning from one to the other. Eventually, `GraphQL::{X}Type` objects will be removed entirely, But this can help during the transition.
@example Applying a function to base object class
# Here's the legacy-style config, which we're calling back to: GraphQL::ObjectType.accepts_definition({ permission_level: ->(defn, value) { defn.metadata[:permission_level] = value } }) class BaseObject < GraphQL::Schema::Object # Setup a named pass-through to the legacy config functions accepts_definition :permission_level end class Account < BaseObject # This value will be passed to the legacy handler: permission_level 1 end # The class gets a reader method which returns the args, # only marginally useful. Account.permission_level # => [1] # The legacy handler is called, as before: Account.graphql_definition.metadata[:permission_level] # => 1
Public Class Methods
extended(child)
click to toggle source
# File lib/graphql/schema/member/accepts_definition.rb, line 45 def self.extended(child) if defined?(child::DefinitionMethods) child::DefinitionMethods.include(AcceptsDefinitionDefinitionMethods) child::DefinitionMethods.prepend(ToGraphQLExtension) else child.extend(AcceptsDefinitionDefinitionMethods) # I tried to use `super`, but super isn't quite right # since the method is defined in the same class itself, # not the superclass child.class_eval do class << self prepend(ToGraphQLExtension) end end end end
included(child)
click to toggle source
# File lib/graphql/schema/member/accepts_definition.rb, line 39 def self.included(child) child.extend(AcceptsDefinitionDefinitionMethods) child.prepend(ToGraphQLExtension) child.prepend(InitializeExtension) end