Sha256: 5f4574f58393afca47bd945b71f49b819947a60d56fa600df8429be2fb02be65

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

module GraphqlPagination
  module CollectionType
    def collection_type(
      collection_base: GraphQL::Schema::Object,
      metadata_type: GraphqlPagination::CollectionMetadataType
    )
      fail CollectionBaseError unless collection_base <= GraphQL::Schema::Object

      @collection_types ||= {}
      @collection_types[collection_base] ||= {}
      @collection_types[collection_base][metadata_type] ||= begin
        type_name = "#{graphql_name}Collection"
        source_type = self

        Class.new(collection_base) do
          graphql_name type_name
          field :collection, [source_type], null: false
          field :metadata, metadata_type, null: false

          def collection
            object
          end

          def metadata
            object
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-pagination-2.1.1 lib/graphql_pagination/collection_type.rb
graphql-pagination-2.1.0 lib/graphql_pagination/collection_type.rb