File: skip_directive.rb

package info (click to toggle)
ruby-graphql-client 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: ruby: 1,878; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require "graphql/client/schema/base_type"

module GraphQL
  class Client
    module Schema
      class SkipDirective
        include BaseType

        # Internal: Construct list wrapper from other BaseType.
        #
        # of_klass - BaseType instance
        def initialize(of_klass)
          unless of_klass.is_a?(BaseType)
            raise TypeError, "expected #{of_klass.inspect} to be a #{BaseType}"
          end

          @of_klass = of_klass
        end

        # Internal: Get wrapped klass.
        #
        # Returns BaseType instance.
        attr_reader :of_klass

        # Internal: Cast JSON value to wrapped value.
        #
        # values - JSON value
        # errors - Errors instance
        #
        # Returns List instance or nil.
        def cast(value, errors)
          case value
          when NilClass
            nil
          else
            of_klass.cast(value, errors)
          end
        end
      end
    end
  end
end