Sha256: f4d26d92c11da1f540b9c4bb81ae6628ba721aedf804cc764af4de31d7ac5006

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

module GraphQL
  module Models
    class ProxyBlock
      def initialize(graph_type, base_model_type, model_type, path, object_to_model)
        @path = path
        @base_model_type = base_model_type
        @model_type = model_type
        @graph_type = graph_type
        @object_to_model = object_to_model
      end

      def types
        GraphQL::Define::TypeDefiner.instance
      end

      def attr(name, **options, &block)
        DefinitionHelpers.define_attribute(@graph_type, @base_model_type, @model_type, @path, name, @object_to_model, options, &block)
      end

      def proxy_to(association, &block)
        DefinitionHelpers.define_proxy(@graph_type, @base_model_type, @model_type, @path, association, @object_to_model, &block)
      end

      def has_one(association, **options)
        DefinitionHelpers.define_has_one(@graph_type, @base_model_type, @model_type, @path, association, @object_to_model, options)
      end

      def has_many_connection(association, **options)
        DefinitionHelpers.define_has_many_connection(@graph_type, @base_model_type, @model_type, @path, association, @object_to_model, options)
      end

      def has_many_array(association, **options)
        DefinitionHelpers.define_has_many_array(@graph_type, @base_model_type, @model_type, @path, association, @object_to_model, options)
      end

      def field(*args, &block)
        defined_field = GraphQL::Define::AssignObjectField.call(@graph_type, *args, &block)

        DefinitionHelpers.register_field_metadata(@graph_type, defined_field.name, {
          macro: :field,
          macro_type: :custom,
          path: @path,
          base_model_type: @base_model_type,
          model_type: @model_type,
          object_to_base_model: @object_to_model
        })

        defined_field
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-activerecord-0.9.1 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.9.0 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.8.0 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.7.3 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.7.2 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.8.0.pre.alpha1 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.7.1 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.7.0 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.6.7 lib/graphql/models/proxy_block.rb
graphql-activerecord-0.6.6 lib/graphql/models/proxy_block.rb