Sha256: e6dcbd95f4e18dbc007cf8f7edbc96ebca9fb4370b9b271f9b2d4018cd99584c

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module GraphQL
  module Types
    module Relay
      module HasNodesField
        def self.included(child_class)
          child_class.field(**field_options, &field_block)
        end

        class << self
          def field_options
            {
              name: "nodes",
              owner: nil,
              type: [GraphQL::Types::Relay::Node, null: true],
              null: false,
              description: "Fetches a list of objects given a list of IDs.",
              relay_nodes_field: true,
            }
          end

          def field_block
            Proc.new {
              argument :ids, "[ID!]!", required: true,
                description: "IDs of the objects."

              def resolve(obj, args, ctx)
                args[:ids].map { |id| ctx.schema.object_from_id(id, ctx) }
              end

              def resolve_field(obj, args, ctx)
                resolve(obj, args, ctx)
              end
            }
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql-1.12.12 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.11 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.10 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.9 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.8 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.7 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.6 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.5 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.4 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.3 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.2 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.1 lib/graphql/types/relay/has_nodes_field.rb
graphql-1.12.0 lib/graphql/types/relay/has_nodes_field.rb