Welcome to mirror list, hosted at ThFree Co, Russian Federation.

field_inspection.rb « graphql « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8730f82b893dafed928220110ef3f21f800a9f33 (plain)
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
# frozen_string_literal: true

module Graphql
  class FieldInspection
    def initialize(field)
      @field = field
    end

    def nested_fields?
      !scalar? && !enum?
    end

    def scalar?
      type.kind.scalar?
    end

    def enum?
      type.kind.enum?
    end

    def type
      @type ||= begin
        field_type = @field.type

        # The type could be nested. For example `[GraphQL::Types::String]`:
        # - List
        # - String!
        # - String
        field_type = field_type.of_type while field_type.respond_to?(:of_type)

        field_type
      end
    end
  end
end