Module: GraphQL::Schema::Member::CachedGraphQLDefinition Private

Included in:
Argument, EnumValue, Field, Interface::DefinitionMethods, GraphQL::Schema::Member, Wrapper
Defined in:
lib/graphql/schema/member/cached_graphql_definition.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Adds a layer of caching over user-supplied .to_graphql methods. Users override .to_graphql, but all runtime code should use .graphql_definition.

See Also:

  • classes that extend this, eg {Schema::Object}

Defined Under Namespace

Modules: DeprecatedToGraphQL

Instance Method Summary collapse

Instance Method Details

#deprecated_to_graphqlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
# File 'lib/graphql/schema/member/cached_graphql_definition.rb', line 25

def deprecated_to_graphql
  case method(:to_graphql).arity
  when 0
    to_graphql
  else
    to_graphql(silence_deprecation_warning: true)
  end
end

#graphql_definition(silence_deprecation_warning: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A cached result of to_graphql. It’s cached here so that user-overridden to_graphql implementations are also cached



14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql/schema/member/cached_graphql_definition.rb', line 14

def graphql_definition(silence_deprecation_warning: false)
  @graphql_definition ||= begin
    unless silence_deprecation_warning
      message = "Legacy `.graphql_definition` objects are deprecated and will be removed in GraphQL-Ruby 2.0. Remove `.graphql_definition` to use a class-based definition instead."
      caller_message = "\n\nCalled on #{self.inspect} from:\n #{caller(1, 25).map { |l| "  #{l}" }.join("\n")}"
      GraphQL::Deprecation.warn(message + caller_message)
    end
    deprecated_to_graphql
  end
end

#initialize_copy(original) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wipe out the cached graphql_definition so that .to_graphql will be called again.



40
41
42
43
# File 'lib/graphql/schema/member/cached_graphql_definition.rb', line 40

def initialize_copy(original)
  super
  @graphql_definition = nil
end

#type_classObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is for a common interface with .define-based types



35
36
37
# File 'lib/graphql/schema/member/cached_graphql_definition.rb', line 35

def type_class
  self
end