Sha256: 76e81bd128d66c850010b78422409273bee804241341e60f41e191ecb5654c4f

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'graphql'

module GraphqlRails
  module Attributes
    # converts string value in to GraphQL type
    class InputTypeParser
      require_relative './type_parseable'

      include TypeParseable

      def initialize(unparsed_type, subtype:)
        @unparsed_type = unparsed_type
        @subtype = subtype
      end

      def graphql_type
        return nil if unparsed_type.nil?

        partly_parsed_type || parsed_type
      end

      def input_type_arg
        if list?
          list_type_arg
        else
          unwrapped_type
        end
      end

      private

      attr_reader :unparsed_type, :subtype

      def unwrapped_type
        raw_unwrapped_type || unwrapped_scalar_type || unwrapped_model_input_type || raise_not_supported_type_error
      end

      def raw_unwrapped_type
        return nil unless raw_graphql_type?

        unwrap_type(unparsed_type)
      end

      def list_type_arg
        if required_inner_type?
          [unwrapped_type]
        else
          [unwrapped_type, null: true]
        end
      end

      def unwrapped_model_input_type
        type_class = graphql_model
        return unless type_class

        type_class.graphql.input(subtype).graphql_input_type
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql_rails-1.2.6 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.2.4 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.2.3 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.2.2 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.2.1 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.2.0 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.1.0 lib/graphql_rails/attributes/input_type_parser.rb
graphql_rails-1.0.0 lib/graphql_rails/attributes/input_type_parser.rb