graphql_rails 1.2.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +18 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile +3 -3
- data/Gemfile.lock +27 -25
- data/docs/README.md +1 -1
- data/docs/components/model.md +39 -5
- data/docs/other_tools/schema_dump.md +8 -8
- data/lib/graphql_rails/attributes/attributable.rb +6 -14
- data/lib/graphql_rails/attributes/attribute.rb +8 -33
- data/lib/graphql_rails/attributes/attribute_configurable.rb +33 -0
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +7 -7
- data/lib/graphql_rails/attributes/input_attribute.rb +19 -13
- data/lib/graphql_rails/attributes/input_type_parser.rb +5 -7
- data/lib/graphql_rails/attributes/type_parseable.rb +32 -11
- data/lib/graphql_rails/attributes/type_parser.rb +4 -9
- data/lib/graphql_rails/concerns/chainable_options.rb +49 -0
- data/lib/graphql_rails/input_configurable.rb +10 -8
- data/lib/graphql_rails/model/build_connection_type/count_items.rb +1 -1
- data/lib/graphql_rails/model/build_connection_type.rb +1 -1
- data/lib/graphql_rails/model/configurable.rb +30 -8
- data/lib/graphql_rails/model/configuration.rb +26 -12
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +23 -21
- data/lib/graphql_rails/model/input.rb +10 -26
- data/lib/graphql_rails/model.rb +1 -1
- data/lib/graphql_rails/router/route.rb +2 -2
- data/lib/graphql_rails/tasks/dump_graphql_schema.rb +14 -28
- data/lib/graphql_rails/tasks/dump_graphql_schemas.rb +57 -0
- data/lib/graphql_rails/tasks/schema.rake +8 -5
- data/lib/graphql_rails/version.rb +1 -1
- metadata +11 -8
- data/.travis.yml +0 -5
| @@ -51,7 +51,9 @@ module GraphqlRails | |
| 51 51 | 
             
                  def paginated_type_arg
         | 
| 52 52 | 
             
                    return graphql_model.graphql.connection_type if graphql_model
         | 
| 53 53 |  | 
| 54 | 
            -
                     | 
| 54 | 
            +
                    error_message = "Unable to paginate #{unparsed_type.inspect}. " \
         | 
| 55 | 
            +
                                    'Pagination is only supported for models which include GraphqlRails::Model'
         | 
| 56 | 
            +
                    raise NotSupportedFeature, error_message
         | 
| 55 57 | 
             
                  end
         | 
| 56 58 |  | 
| 57 59 | 
             
                  def list_type_arg
         | 
| @@ -107,14 +109,7 @@ module GraphqlRails | |
| 107 109 | 
             
                  end
         | 
| 108 110 |  | 
| 109 111 | 
             
                  def type_by_name
         | 
| 110 | 
            -
                    unwrapped_scalar_type ||  | 
| 111 | 
            -
                  end
         | 
| 112 | 
            -
             | 
| 113 | 
            -
                  def unwrapped_model_type
         | 
| 114 | 
            -
                    type_class = graphql_model
         | 
| 115 | 
            -
                    return unless type_class
         | 
| 116 | 
            -
             | 
| 117 | 
            -
                    type_class.graphql.graphql_type
         | 
| 112 | 
            +
                    unwrapped_scalar_type || graphql_type_object || raise_not_supported_type_error
         | 
| 118 113 | 
             
                  end
         | 
| 119 114 | 
             
                end
         | 
| 120 115 | 
             
              end
         | 
| @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module GraphqlRails
         | 
| 4 | 
            +
              # Allows defining methods chained way
         | 
| 5 | 
            +
              module ChainableOptions
         | 
| 6 | 
            +
                NOT_SET = Object.new
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # nodoc
         | 
| 9 | 
            +
                module ClassMethods
         | 
| 10 | 
            +
                  def chainable_option(option_name, default: nil)
         | 
| 11 | 
            +
                    define_method(option_name) do |value = NOT_SET|
         | 
| 12 | 
            +
                      get_or_set_chainable_option(option_name, value, default: default)
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.included(base)
         | 
| 18 | 
            +
                  base.extend(ClassMethods)
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def initialize_copy(other)
         | 
| 22 | 
            +
                  super
         | 
| 23 | 
            +
                  @chainable_option = other.instance_variable_get(:@chainable_option).dup
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def with(**options)
         | 
| 27 | 
            +
                  options.each do |method_name, args|
         | 
| 28 | 
            +
                    send_args = [method_name]
         | 
| 29 | 
            +
                    send_args << args if method(method_name).parameters.present?
         | 
| 30 | 
            +
                    public_send(*send_args)
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                  self
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                private
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def fetch_chainable_option(option_name, *default, &block)
         | 
| 38 | 
            +
                  @chainable_option.fetch(option_name.to_sym, *default, &block)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def get_or_set_chainable_option(option_name, value = NOT_SET, default: nil)
         | 
| 42 | 
            +
                  @chainable_option ||= {}
         | 
| 43 | 
            +
                  return fetch_chainable_option(option_name, default) if value == NOT_SET
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  @chainable_option[option_name.to_sym] = value
         | 
| 46 | 
            +
                  self
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
            end
         | 
| @@ -3,9 +3,14 @@ | |
| 3 3 | 
             
            module GraphqlRails
         | 
| 4 4 | 
             
              # contains configuration options related with inputs
         | 
| 5 5 | 
             
              module InputConfigurable
         | 
| 6 | 
            -
                def permit(* | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 6 | 
            +
                def permit(*args)
         | 
| 7 | 
            +
                  args.each do |arg|
         | 
| 8 | 
            +
                    if arg.is_a? Hash
         | 
| 9 | 
            +
                      arg.each { |attribute, type| permit_input(attribute, type: type) }
         | 
| 10 | 
            +
                    else
         | 
| 11 | 
            +
                      permit_input(arg)
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                  end
         | 
| 9 14 | 
             
                  self
         | 
| 10 15 | 
             
                end
         | 
| 11 16 |  | 
| @@ -37,11 +42,8 @@ module GraphqlRails | |
| 37 42 | 
             
                end
         | 
| 38 43 |  | 
| 39 44 | 
             
                def build_input_attribute(name, options: {}, **other_options)
         | 
| 40 | 
            -
                   | 
| 41 | 
            -
             | 
| 42 | 
            -
                    options: input_attribute_options.merge(options),
         | 
| 43 | 
            -
                    **other_options
         | 
| 44 | 
            -
                  )
         | 
| 45 | 
            +
                  input_options = input_attribute_options.merge(options)
         | 
| 46 | 
            +
                  Attributes::InputAttribute.new(name.to_s, config: self).with(options: input_options, **other_options)
         | 
| 45 47 | 
             
                end
         | 
| 46 48 | 
             
              end
         | 
| 47 49 | 
             
            end
         | 
| @@ -2,25 +2,47 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            module GraphqlRails
         | 
| 4 4 | 
             
              module Model
         | 
| 5 | 
            -
                #  | 
| 6 | 
            -
                # | 
| 5 | 
            +
                # Contains methods which are shared between various configurations.
         | 
| 6 | 
            +
                #
         | 
| 7 | 
            +
                # Expects `default_name` to be defined.
         | 
| 8 | 
            +
                # Expects `build_attribute(attr_name)` method to be defined.
         | 
| 7 9 | 
             
                module Configurable
         | 
| 10 | 
            +
                  require 'active_support/concern'
         | 
| 11 | 
            +
                  require 'graphql_rails/concerns/chainable_options'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  extend ActiveSupport::Concern
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  included do
         | 
| 16 | 
            +
                    include GraphqlRails::ChainableOptions
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    chainable_option :description
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def initialize_copy(other)
         | 
| 22 | 
            +
                    super
         | 
| 23 | 
            +
                    @type_name = nil
         | 
| 24 | 
            +
                    @attributes = other.attributes.transform_values(&:dup)
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 8 27 | 
             
                  def attributes
         | 
| 9 28 | 
             
                    @attributes ||= {}
         | 
| 10 29 | 
             
                  end
         | 
| 11 30 |  | 
| 12 | 
            -
                  def name( | 
| 13 | 
            -
                     | 
| 14 | 
            -
                    @name || default_name
         | 
| 31 | 
            +
                  def name(*args)
         | 
| 32 | 
            +
                    get_or_set_chainable_option(:name, *args) || default_name
         | 
| 15 33 | 
             
                  end
         | 
| 16 34 |  | 
| 17 35 | 
             
                  def type_name
         | 
| 18 36 | 
             
                    @type_name ||= "#{name.camelize}Type#{SecureRandom.hex}"
         | 
| 19 37 | 
             
                  end
         | 
| 20 38 |  | 
| 21 | 
            -
                  def  | 
| 22 | 
            -
                     | 
| 23 | 
            -
             | 
| 39 | 
            +
                  def attribute(attribute_name, **attribute_options)
         | 
| 40 | 
            +
                    key = attribute_name.to_s
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    attributes[key] ||= build_attribute(attribute_name).tap do |new_attribute|
         | 
| 43 | 
            +
                      new_attribute.with(**attribute_options) unless attribute_options.empty?
         | 
| 44 | 
            +
                      yield(new_attribute) if block_given?
         | 
| 45 | 
            +
                    end
         | 
| 24 46 | 
             
                  end
         | 
| 25 47 | 
             
                end
         | 
| 26 48 | 
             
              end
         | 
| @@ -2,7 +2,6 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'graphql_rails/attributes'
         | 
| 4 4 | 
             
            require 'graphql_rails/model/find_or_build_graphql_type'
         | 
| 5 | 
            -
            require 'graphql_rails/model/build_enum_type'
         | 
| 6 5 | 
             
            require 'graphql_rails/model/input'
         | 
| 7 6 | 
             
            require 'graphql_rails/model/configurable'
         | 
| 8 7 | 
             
            require 'graphql_rails/model/build_connection_type'
         | 
| @@ -11,6 +10,7 @@ module GraphqlRails | |
| 11 10 | 
             
              module Model
         | 
| 12 11 | 
             
                # stores information about model specific config, like attributes and types
         | 
| 13 12 | 
             
                class Configuration
         | 
| 13 | 
            +
                  include ChainableOptions
         | 
| 14 14 | 
             
                  include Configurable
         | 
| 15 15 |  | 
| 16 16 | 
             
                  def initialize(model_class)
         | 
| @@ -22,22 +22,14 @@ module GraphqlRails | |
| 22 22 | 
             
                    @connection_type = nil
         | 
| 23 23 | 
             
                    @graphql_type = nil
         | 
| 24 24 | 
             
                    @input = other.instance_variable_get(:@input)&.transform_values(&:dup)
         | 
| 25 | 
            -
                    @attributes = other.instance_variable_get(:@attributes)&.transform_values(&:dup)
         | 
| 26 25 | 
             
                  end
         | 
| 27 26 |  | 
| 28 27 | 
             
                  def attribute(attribute_name, **attribute_options)
         | 
| 29 28 | 
             
                    key = attribute_name.to_s
         | 
| 30 29 |  | 
| 31 | 
            -
                    attributes[key] ||=  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
                      attribute_options.each do |method_name, args|
         | 
| 35 | 
            -
                        send_args = [method_name]
         | 
| 36 | 
            -
                        send_args << args if attribute.method(method_name).parameters.present?
         | 
| 37 | 
            -
                        attribute.public_send(*send_args)
         | 
| 38 | 
            -
                      end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                      yield(attribute) if block_given?
         | 
| 30 | 
            +
                    attributes[key] ||= build_attribute(attribute_name).tap do |new_attribute|
         | 
| 31 | 
            +
                      new_attribute.with(**attribute_options)
         | 
| 32 | 
            +
                      yield(new_attribute) if block_given?
         | 
| 41 33 | 
             
                    end
         | 
| 42 34 | 
             
                  end
         | 
| 43 35 |  | 
| @@ -68,13 +60,35 @@ module GraphqlRails | |
| 68 60 | 
             
                    @connection_type ||= BuildConnectionType.call(graphql_type)
         | 
| 69 61 | 
             
                  end
         | 
| 70 62 |  | 
| 63 | 
            +
                  def with_ensured_fields!
         | 
| 64 | 
            +
                    return self if @graphql_type.blank?
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    reset_graphql_type if attributes.any? && graphql_type.fields.length != attributes.length
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    self
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
             | 
| 71 71 | 
             
                  private
         | 
| 72 72 |  | 
| 73 73 | 
             
                  attr_reader :model_class
         | 
| 74 74 |  | 
| 75 | 
            +
                  def build_attribute(attribute_name)
         | 
| 76 | 
            +
                    Attributes::Attribute.new(attribute_name)
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
             | 
| 75 79 | 
             
                  def default_name
         | 
| 76 80 | 
             
                    @default_name ||= model_class.name.split('::').last
         | 
| 77 81 | 
             
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  def reset_graphql_type
         | 
| 84 | 
            +
                    @graphql_type = FindOrBuildGraphqlType.call(
         | 
| 85 | 
            +
                      name: name,
         | 
| 86 | 
            +
                      description: description,
         | 
| 87 | 
            +
                      attributes: attributes,
         | 
| 88 | 
            +
                      type_name: type_name,
         | 
| 89 | 
            +
                      force_define_attributes: true
         | 
| 90 | 
            +
                    )
         | 
| 91 | 
            +
                  end
         | 
| 78 92 | 
             
                end
         | 
| 79 93 | 
             
              end
         | 
| 80 94 | 
             
            end
         | 
| @@ -10,20 +10,21 @@ module GraphqlRails | |
| 10 10 |  | 
| 11 11 | 
             
                  include ::GraphqlRails::Service
         | 
| 12 12 |  | 
| 13 | 
            -
                  def initialize(name:, description:, attributes:, type_name:)
         | 
| 13 | 
            +
                  def initialize(name:, description:, attributes:, type_name:, force_define_attributes: false)
         | 
| 14 14 | 
             
                    @name = name
         | 
| 15 15 | 
             
                    @description = description
         | 
| 16 16 | 
             
                    @attributes = attributes
         | 
| 17 17 | 
             
                    @type_name = type_name
         | 
| 18 | 
            +
                    @force_define_attributes = force_define_attributes
         | 
| 18 19 | 
             
                  end
         | 
| 19 20 |  | 
| 20 21 | 
             
                  def call
         | 
| 21 | 
            -
                    klass.tap { add_fields_to_graphql_type if new_class? }
         | 
| 22 | 
            +
                    klass.tap { add_fields_to_graphql_type if new_class? || force_define_attributes }
         | 
| 22 23 | 
             
                  end
         | 
| 23 24 |  | 
| 24 25 | 
             
                  private
         | 
| 25 26 |  | 
| 26 | 
            -
                  attr_reader :name, :description, :attributes, :type_name
         | 
| 27 | 
            +
                  attr_reader :name, :description, :attributes, :type_name, :force_define_attributes
         | 
| 27 28 |  | 
| 28 29 | 
             
                  delegate :klass, :new_class?, to: :type_class_finder
         | 
| 29 30 |  | 
| @@ -36,29 +37,30 @@ module GraphqlRails | |
| 36 37 | 
             
                  end
         | 
| 37 38 |  | 
| 38 39 | 
             
                  def add_fields_to_graphql_type
         | 
| 39 | 
            -
                     | 
| 40 | 
            +
                    scalar_attributes, dynamic_attributes = attributes.values.partition(&:scalar_type?)
         | 
| 40 41 |  | 
| 41 | 
            -
                     | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
                          name: name, description: description,
         | 
| 45 | 
            -
                          attributes: attributes, type_name: type_name
         | 
| 46 | 
            -
                        )
         | 
| 47 | 
            -
                      end
         | 
| 48 | 
            -
                      AddFieldsToGraphqlType.call(klass: klass, attributes: dynamic_attributes)
         | 
| 49 | 
            -
                    end
         | 
| 42 | 
            +
                    AddFieldsToGraphqlType.call(klass: klass, attributes: scalar_attributes)
         | 
| 43 | 
            +
                    dynamic_attributes.each { |attribute| find_or_build_dynamic_type(attribute) }
         | 
| 44 | 
            +
                    AddFieldsToGraphqlType.call(klass: klass, attributes: dynamic_attributes)
         | 
| 50 45 | 
             
                  end
         | 
| 51 46 |  | 
| 52 | 
            -
                  def  | 
| 53 | 
            -
                     | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                        attribute.graphql_model.graphql.type_name
         | 
| 59 | 
            -
                      )
         | 
| 47 | 
            +
                  def find_or_build_dynamic_type(attribute)
         | 
| 48 | 
            +
                    graphql_model = attribute.graphql_model
         | 
| 49 | 
            +
                    if graphql_model
         | 
| 50 | 
            +
                      find_or_build_graphql_model_type(graphql_model)
         | 
| 51 | 
            +
                    else
         | 
| 52 | 
            +
                      AddFieldsToGraphqlType.call(klass: klass, attributes: [attribute])
         | 
| 60 53 | 
             
                    end
         | 
| 61 54 | 
             
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def find_or_build_graphql_model_type(graphql_model)
         | 
| 57 | 
            +
                    self.class.call(
         | 
| 58 | 
            +
                      name: graphql_model.graphql.name,
         | 
| 59 | 
            +
                      description: graphql_model.graphql.description,
         | 
| 60 | 
            +
                      attributes: graphql_model.graphql.attributes,
         | 
| 61 | 
            +
                      type_name: graphql_model.graphql.type_name
         | 
| 62 | 
            +
                    )
         | 
| 63 | 
            +
                  end
         | 
| 62 64 | 
             
                end
         | 
| 63 65 | 
             
              end
         | 
| 64 66 | 
             
            end
         | 
| @@ -1,58 +1,42 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'graphql_rails/model/build_graphql_input_type'
         | 
| 4 | 
            -
            require 'graphql_rails/model/configurable'
         | 
| 5 | 
            -
             | 
| 6 3 | 
             
            module GraphqlRails
         | 
| 7 4 | 
             
              module Model
         | 
| 8 5 | 
             
                # stores information about model input specific config, like attributes and types
         | 
| 9 6 | 
             
                class Input
         | 
| 7 | 
            +
                  require 'graphql_rails/concerns/chainable_options'
         | 
| 8 | 
            +
                  require 'graphql_rails/model/configurable'
         | 
| 9 | 
            +
                  require 'graphql_rails/model/build_graphql_input_type'
         | 
| 10 | 
            +
             | 
| 10 11 | 
             
                  include Configurable
         | 
| 11 12 |  | 
| 13 | 
            +
                  chainable_option :enum
         | 
| 14 | 
            +
             | 
| 12 15 | 
             
                  def initialize(model_class, input_name_suffix)
         | 
| 13 16 | 
             
                    @model_class = model_class
         | 
| 14 17 | 
             
                    @input_name_suffix = input_name_suffix
         | 
| 15 18 | 
             
                  end
         | 
| 16 19 |  | 
| 17 | 
            -
                  def initialize_copy(other)
         | 
| 18 | 
            -
                    super
         | 
| 19 | 
            -
                    @attributes = other.instance_variable_get(:@attributes)&.transform_values(&:dup)
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 20 | 
             
                  def graphql_input_type
         | 
| 23 21 | 
             
                    @graphql_input_type ||= BuildGraphqlInputType.call(
         | 
| 24 22 | 
             
                      name: name, description: description, attributes: attributes
         | 
| 25 23 | 
             
                    )
         | 
| 26 24 | 
             
                  end
         | 
| 27 25 |  | 
| 28 | 
            -
                  def attribute(attribute_name, type: nil, enum: nil, **attribute_options)
         | 
| 29 | 
            -
                    input_type = attribute_type(attribute_name, type: type, enum: enum, **attribute_options)
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                    attributes[attribute_name.to_s] = Attributes::InputAttribute.new(
         | 
| 32 | 
            -
                      attribute_name, type: input_type, **attribute_options
         | 
| 33 | 
            -
                    )
         | 
| 34 | 
            -
                  end
         | 
| 35 | 
            -
             | 
| 36 26 | 
             
                  private
         | 
| 37 27 |  | 
| 38 28 | 
             
                  attr_reader :input_name_suffix, :model_class
         | 
| 39 29 |  | 
| 30 | 
            +
                  def build_attribute(attribute_name)
         | 
| 31 | 
            +
                    Attributes::InputAttribute.new(attribute_name, config: self)
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 40 34 | 
             
                  def default_name
         | 
| 41 35 | 
             
                    @default_name ||= begin
         | 
| 42 36 | 
             
                      suffix = input_name_suffix ? input_name_suffix.to_s.camelize : ''
         | 
| 43 37 | 
             
                      "#{model_class.name.split('::').last}#{suffix}Input"
         | 
| 44 38 | 
             
                    end
         | 
| 45 39 | 
             
                  end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  def attribute_type(attribute_name, type:, enum:, description: nil, **_other)
         | 
| 48 | 
            -
                    return type unless enum
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                    BuildEnumType.call(
         | 
| 51 | 
            -
                      "#{name}_#{attribute_name}_enum",
         | 
| 52 | 
            -
                      allowed_values: enum,
         | 
| 53 | 
            -
                      description: description
         | 
| 54 | 
            -
                    )
         | 
| 55 | 
            -
                  end
         | 
| 56 40 | 
             
                end
         | 
| 57 41 | 
             
              end
         | 
| 58 42 | 
             
            end
         | 
    
        data/lib/graphql_rails/model.rb
    CHANGED
    
    
| @@ -6,7 +6,7 @@ module GraphqlRails | |
| 6 6 | 
             
              class Router
         | 
| 7 7 | 
             
                # Generic class for any type graphql action. Should not be used directly
         | 
| 8 8 | 
             
                class Route
         | 
| 9 | 
            -
                  attr_reader :name, :module_name, :on, :relative_path
         | 
| 9 | 
            +
                  attr_reader :name, :module_name, :on, :relative_path, :groups
         | 
| 10 10 |  | 
| 11 11 | 
             
                  def initialize(name, to: '', on:, groups: nil, **options)
         | 
| 12 12 | 
             
                    @name = name.to_s.camelize(:lower)
         | 
| @@ -43,7 +43,7 @@ module GraphqlRails | |
| 43 43 |  | 
| 44 44 | 
             
                  private
         | 
| 45 45 |  | 
| 46 | 
            -
                  attr_reader :function | 
| 46 | 
            +
                  attr_reader :function
         | 
| 47 47 |  | 
| 48 48 | 
             
                  def resolver
         | 
| 49 49 | 
             
                    @resolver ||= Controller::BuildControllerActionResolver.call(route: self)
         | 
| @@ -7,51 +7,37 @@ module GraphqlRails | |
| 7 7 |  | 
| 8 8 | 
             
                class MissingGraphqlRouterError < GraphqlRails::Error; end
         | 
| 9 9 |  | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 12 | 
            -
                def self.call(*args)
         | 
| 13 | 
            -
                  new(*args).call
         | 
| 10 | 
            +
                def self.call(**args)
         | 
| 11 | 
            +
                  new(**args).call
         | 
| 14 12 | 
             
                end
         | 
| 15 13 |  | 
| 16 | 
            -
                def initialize( | 
| 17 | 
            -
                  @ | 
| 14 | 
            +
                def initialize(group:, router:, dump_dir: nil)
         | 
| 15 | 
            +
                  @group = group
         | 
| 16 | 
            +
                  @router = router
         | 
| 17 | 
            +
                  @dump_dir = dump_dir
         | 
| 18 18 | 
             
                end
         | 
| 19 19 |  | 
| 20 20 | 
             
                def call
         | 
| 21 | 
            -
                  validate
         | 
| 22 21 | 
             
                  File.write(schema_path, schema.to_definition)
         | 
| 23 22 | 
             
                end
         | 
| 24 23 |  | 
| 25 24 | 
             
                private
         | 
| 26 25 |  | 
| 27 | 
            -
                 | 
| 28 | 
            -
                  return if router
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  error_message = \
         | 
| 31 | 
            -
                    'GraphqlRouter is missing. ' \
         | 
| 32 | 
            -
                    'Run `rails g graphql_rails:install` to build it'
         | 
| 33 | 
            -
                  raise MissingGraphqlRouterError, error_message
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def router
         | 
| 37 | 
            -
                  @router ||= '::GraphqlRouter'.safe_constantize
         | 
| 38 | 
            -
                end
         | 
| 26 | 
            +
                attr_reader :router, :group
         | 
| 39 27 |  | 
| 40 28 | 
             
                def schema
         | 
| 41 | 
            -
                  @schema ||=  | 
| 29 | 
            +
                  @schema ||= router.graphql_schema(group.presence)
         | 
| 42 30 | 
             
                end
         | 
| 43 31 |  | 
| 44 32 | 
             
                def schema_path
         | 
| 45 | 
            -
                   | 
| 46 | 
            -
             | 
| 33 | 
            +
                  FileUtils.mkdir_p(dump_dir)
         | 
| 34 | 
            +
                  file_name = group.present? ? "graphql_#{group}_schema.graphql" : 'graphql_schema.graphql'
         | 
| 47 35 |  | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
                  FileUtils.mkdir_p(schema_folder_path)
         | 
| 52 | 
            -
                  file_name = name.present? ? "graphql_#{name}_schema.graphql" : 'graphql_schema.graphql'
         | 
| 36 | 
            +
                  "#{dump_dir}/#{file_name}"
         | 
| 37 | 
            +
                end
         | 
| 53 38 |  | 
| 54 | 
            -
             | 
| 39 | 
            +
                def dump_dir
         | 
| 40 | 
            +
                  @dump_dir ||= Rails.root.join('spec/fixtures').to_s
         | 
| 55 41 | 
             
                end
         | 
| 56 42 | 
             
              end
         | 
| 57 43 | 
             
            end
         | 
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'graphql_rails/tasks/dump_graphql_schema'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module GraphqlRails
         | 
| 6 | 
            +
              # Generates graphql schema dump files
         | 
| 7 | 
            +
              class DumpGraphqlSchemas
         | 
| 8 | 
            +
                require 'graphql_rails/errors/error'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                class MissingGraphqlRouterError < GraphqlRails::Error; end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def self.call(**args)
         | 
| 13 | 
            +
                  new(**args).call
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def initialize(dump_dir:, groups: nil)
         | 
| 17 | 
            +
                  @groups = groups.presence
         | 
| 18 | 
            +
                  @dump_dir = dump_dir
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def call
         | 
| 22 | 
            +
                  validate
         | 
| 23 | 
            +
                  return dump_default_schema if groups.empty?
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  groups.each { |group| dump_graphql_schema(group) }
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                private
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                attr_reader :dump_dir
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def dump_default_schema
         | 
| 33 | 
            +
                  dump_graphql_schema('')
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def dump_graphql_schema(group)
         | 
| 37 | 
            +
                  DumpGraphqlSchema.call(group: group, router: router, dump_dir: dump_dir)
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def validate
         | 
| 41 | 
            +
                  return if router
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  error_message = \
         | 
| 44 | 
            +
                    'GraphqlRouter is missing. ' \
         | 
| 45 | 
            +
                    'Run `rails g graphql_rails:install` to build it'
         | 
| 46 | 
            +
                  raise MissingGraphqlRouterError, error_message
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                def router
         | 
| 50 | 
            +
                  @router ||= '::GraphqlRouter'.safe_constantize
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def groups
         | 
| 54 | 
            +
                  @groups ||= router.routes.flat_map(&:groups).uniq
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         | 
| @@ -1,14 +1,17 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'graphql_rails/tasks/ | 
| 3 | 
            +
            require 'graphql_rails/tasks/dump_graphql_schemas'
         | 
| 4 4 |  | 
| 5 5 | 
             
            namespace :graphql_rails do
         | 
| 6 6 | 
             
              namespace :schema do
         | 
| 7 7 | 
             
                desc 'Dump GraphQL schema'
         | 
| 8 | 
            -
                task(: | 
| 9 | 
            -
                   | 
| 10 | 
            -
                   | 
| 11 | 
            -
                   | 
| 8 | 
            +
                task(dump: :environment) do |_, args|
         | 
| 9 | 
            +
                  groups_from_args = args.extras
         | 
| 10 | 
            +
                  groups_from_env = ENV['SCHEMA_GROUP_NAME'].to_s.split(',').map(&:strip)
         | 
| 11 | 
            +
                  groups = groups_from_args + groups_from_env
         | 
| 12 | 
            +
                  dump_dir = ENV.fetch('GRAPHQL_SCHEMA_DUMP_DIR') { Rails.root.join('spec/fixtures').to_s }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  GraphqlRails::DumpGraphqlSchemas.call(groups: groups, dump_dir: dump_dir)
         | 
| 12 15 | 
             
                end
         | 
| 13 16 | 
             
              end
         | 
| 14 17 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: graphql_rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Povilas Jurčys
         | 
| 8 | 
            -
            autorequire:
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-12-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: graphql
         | 
| @@ -128,19 +128,19 @@ dependencies: | |
| 128 128 | 
             
                - - "~>"
         | 
| 129 129 | 
             
                  - !ruby/object:Gem::Version
         | 
| 130 130 | 
             
                    version: '6'
         | 
| 131 | 
            -
            description:
         | 
| 131 | 
            +
            description: 
         | 
| 132 132 | 
             
            email:
         | 
| 133 133 | 
             
            - po.jurcys@gmail.com
         | 
| 134 134 | 
             
            executables: []
         | 
| 135 135 | 
             
            extensions: []
         | 
| 136 136 | 
             
            extra_rdoc_files: []
         | 
| 137 137 | 
             
            files:
         | 
| 138 | 
            +
            - ".github/workflows/ruby.yml"
         | 
| 138 139 | 
             
            - ".gitignore"
         | 
| 139 140 | 
             
            - ".hound.yml"
         | 
| 140 141 | 
             
            - ".rspec"
         | 
| 141 142 | 
             
            - ".rubocop.yml"
         | 
| 142 143 | 
             
            - ".ruby-version"
         | 
| 143 | 
            -
            - ".travis.yml"
         | 
| 144 144 | 
             
            - CHANGELOG.md
         | 
| 145 145 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 146 146 | 
             
            - Gemfile
         | 
| @@ -174,12 +174,14 @@ files: | |
| 174 174 | 
             
            - lib/graphql_rails/attributes.rb
         | 
| 175 175 | 
             
            - lib/graphql_rails/attributes/attributable.rb
         | 
| 176 176 | 
             
            - lib/graphql_rails/attributes/attribute.rb
         | 
| 177 | 
            +
            - lib/graphql_rails/attributes/attribute_configurable.rb
         | 
| 177 178 | 
             
            - lib/graphql_rails/attributes/attribute_name_parser.rb
         | 
| 178 179 | 
             
            - lib/graphql_rails/attributes/input_attribute.rb
         | 
| 179 180 | 
             
            - lib/graphql_rails/attributes/input_type_parser.rb
         | 
| 180 181 | 
             
            - lib/graphql_rails/attributes/type_name_info.rb
         | 
| 181 182 | 
             
            - lib/graphql_rails/attributes/type_parseable.rb
         | 
| 182 183 | 
             
            - lib/graphql_rails/attributes/type_parser.rb
         | 
| 184 | 
            +
            - lib/graphql_rails/concerns/chainable_options.rb
         | 
| 183 185 | 
             
            - lib/graphql_rails/concerns/service.rb
         | 
| 184 186 | 
             
            - lib/graphql_rails/controller.rb
         | 
| 185 187 | 
             
            - lib/graphql_rails/controller/action.rb
         | 
| @@ -226,13 +228,14 @@ files: | |
| 226 228 | 
             
            - lib/graphql_rails/router/schema_builder.rb
         | 
| 227 229 | 
             
            - lib/graphql_rails/rspec_controller_helpers.rb
         | 
| 228 230 | 
             
            - lib/graphql_rails/tasks/dump_graphql_schema.rb
         | 
| 231 | 
            +
            - lib/graphql_rails/tasks/dump_graphql_schemas.rb
         | 
| 229 232 | 
             
            - lib/graphql_rails/tasks/schema.rake
         | 
| 230 233 | 
             
            - lib/graphql_rails/version.rb
         | 
| 231 234 | 
             
            homepage: https://github.com/samesystem/graphql_rails
         | 
| 232 235 | 
             
            licenses:
         | 
| 233 236 | 
             
            - MIT
         | 
| 234 237 | 
             
            metadata: {}
         | 
| 235 | 
            -
            post_install_message:
         | 
| 238 | 
            +
            post_install_message: 
         | 
| 236 239 | 
             
            rdoc_options: []
         | 
| 237 240 | 
             
            require_paths:
         | 
| 238 241 | 
             
            - lib
         | 
| @@ -247,8 +250,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 247 250 | 
             
                - !ruby/object:Gem::Version
         | 
| 248 251 | 
             
                  version: '0'
         | 
| 249 252 | 
             
            requirements: []
         | 
| 250 | 
            -
            rubygems_version: 3. | 
| 251 | 
            -
            signing_key:
         | 
| 253 | 
            +
            rubygems_version: 3.2.15
         | 
| 254 | 
            +
            signing_key: 
         | 
| 252 255 | 
             
            specification_version: 4
         | 
| 253 256 | 
             
            summary: Rails style structure for GraphQL API.
         | 
| 254 257 | 
             
            test_files: []
         |