Sha256: d1e18f3fa1c999bb4947ea8e7f30ff5ff1a4bf6ea0e42ce8858956d87f4f7a94

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

module GraphQL
  class Directive
    include GraphQL::Define::InstanceDefinable
    accepts_definitions :locations, :name, :description, :include_proc, argument: GraphQL::Define::AssignArgument

    attr_accessor :locations, :arguments, :name, :description

    LOCATIONS = [
      QUERY =               :QUERY,
      MUTATION =            :MUTATION,
      SUBSCRIPTION =        :SUBSCRIPTION,
      FIELD =               :FIELD,
      FRAGMENT_DEFINITION = :FRAGMENT_DEFINITION,
      FRAGMENT_SPREAD =     :FRAGMENT_SPREAD,
      INLINE_FRAGMENT =     :INLINE_FRAGMENT,
    ]

    def initialize
      @arguments = {}
    end

    def include?(arguments)
      @include_proc.call(arguments)
    end

    def include_proc=(include_proc)
      @include_proc = include_proc
    end

    def to_s
      "<GraphQL::Directive #{name}>"
    end

    def on_field?
      locations.include?(FIELD)
    end

    def on_fragment?
      locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT)
    end

    def on_operation?
      locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION)
    end
  end
end

require "graphql/directive/include_directive"
require "graphql/directive/skip_directive"

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.16.1 lib/graphql/directive.rb
graphql-0.16.0 lib/graphql/directive.rb
graphql-0.15.3 lib/graphql/directive.rb
graphql-0.15.2 lib/graphql/directive.rb
graphql-0.14.2 lib/graphql/directive.rb
graphql-0.15.1 lib/graphql/directive.rb
graphql-0.15.0 lib/graphql/directive.rb
graphql-0.14.1 lib/graphql/directive.rb