Sha256: 2ecd09cc9b29fdce12f1309845c56ea668afbe455c785191bb09d559f4bba8c9

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true
module GraphQL
  # There are two ways to apply the deprecated `!` DSL to class-style schema definitions:
  #
  # 1. Scoped by file (CRuby only), add to the top of the file:
  #
  #      using GraphQL::DeprecationDSL
  #
  #   (This is a "refinement", there are also other ways to scope it.)
  #
  # 2. Global application, add before schema definition:
  #
  #      GraphQL::DeprecationDSL.activate
  #
  module DeprecatedDSL
    TYPE_CLASSES = [
      GraphQL::Schema::Scalar,
      GraphQL::Schema::Enum,
      GraphQL::Schema::InputObject,
      GraphQL::Schema::Union,
      GraphQL::Schema::Interface,
      GraphQL::Schema::Object,
    ]

    def self.activate
      deprecated_caller = caller(1, 1).first
      GraphQL::Deprecation.warn "DeprecatedDSL will be removed from GraphQL-Ruby 2.0, use `.to_non_null_type` instead of `!` and remove `.activate` from #{deprecated_caller}"
      TYPE_CLASSES.each { |c| c.extend(Methods) }
      GraphQL::Schema::List.include(Methods)
      GraphQL::Schema::NonNull.include(Methods)
    end

    module Methods
      def !
        deprecated_caller = caller(1, 1).first
        GraphQL::Deprecation.warn "DeprecatedDSL will be removed from GraphQL-Ruby 2.0, use `.to_non_null_type` instead of `!` at #{deprecated_caller}"
        to_non_null_type
      end
    end

    TYPE_CLASSES.each do |type_class|
      refine type_class.singleton_class do
        include Methods
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
graphql-1.12.17 lib/graphql/deprecated_dsl.rb
graphql-1.12.16 lib/graphql/deprecated_dsl.rb
graphql-1.12.15 lib/graphql/deprecated_dsl.rb
graphql-1.12.14 lib/graphql/deprecated_dsl.rb
graphql-1.12.13 lib/graphql/deprecated_dsl.rb
graphql-1.12.12 lib/graphql/deprecated_dsl.rb
graphql-1.12.11 lib/graphql/deprecated_dsl.rb
graphql-1.12.10 lib/graphql/deprecated_dsl.rb
graphql-1.12.9 lib/graphql/deprecated_dsl.rb
graphql-1.12.8 lib/graphql/deprecated_dsl.rb
graphql-1.12.7 lib/graphql/deprecated_dsl.rb
graphql-1.12.6 lib/graphql/deprecated_dsl.rb
graphql-1.12.5 lib/graphql/deprecated_dsl.rb
graphql-1.12.4 lib/graphql/deprecated_dsl.rb
graphql-1.12.3 lib/graphql/deprecated_dsl.rb
graphql-1.12.2 lib/graphql/deprecated_dsl.rb