Sha256: adc2a392cc16b818cbf123f71252aab454a8ea80709dbace0a778fdca6d290c5

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 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
        description "Returns a boolean indicating whether the viewing user has starred this starrable."

        resolve ->(object, arguments, context) do
          if context[:viewer]
            context[:viewer].starred?(object)
          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

4 entries across 4 versions & 1 rubygems

Version Path
graphql-1.8.0.pre10 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.0.pre9 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.0.pre8 spec/fixtures/upgrader/starrable.original.rb
graphql-1.8.0.pre7 spec/fixtures/upgrader/starrable.original.rb