Sha256: 8b6d6d466abba012e5cf70be0b8794ff25ee2b4ca23fba924346d4092d208db2

Contents?: true

Size: 1.3 KB

Versions: 36

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Platform
  module Interfaces
    Starrable = GraphQL::InterfaceType.define do
      name "Starrable"
      description "Things that can be starred."

      global_id_field :id

      field :viewerHasStarred, !types.Boolean do
        argument :preceedsConnectionMethod, types.Boolean
        description "Returns a boolean indicating whether the viewing user has starred this starrable."

        resolve ->(object, arguments, context) do
          if context[:viewer]
            ->(test_inner_proc) do
              context[:viewer].starred?(object)
            end
          else
            false
          end
        end
      end

      connection :stargazers, -> { !Connections::Stargazer } do
        description "A list of users who have starred this starrable."

        argument :orderBy, Inputs::StarOrder, "Order for connection"

        resolve ->(object, arguments, context) do
          scope = case object
          when Repository
            object.stars
          when Gist
            GistStar.where(gist_id: object.id)
          end

          table = scope.table_name
          if order_by = arguments["orderBy"]
            scope = scope.order("#{table}.#{order_by["field"]} #{order_by["direction"]}")
          end

          scope
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.11 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.10 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.9 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.8 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.7 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.6 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.5 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.4 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.3 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.2 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.17 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.16 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.1 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.0 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.15 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.0.pre4 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.14 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.0.pre3 spec/fixtures/upgrader/starrable.original.rb
graphql-1.9.0.pre2 spec/fixtures/upgrader/starrable.original.rb