Sha256: dbffe9bfd8ebc8305b6f88a6ecb411458f73992d9b124af859d9d9f05d4003a0

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

module Platform
  module Interfaces
    module Subscribable
      include Platform::Interfaces::Base
      description "Entities that can be subscribed to for web and email notifications."

      field :id, GraphQL::ID_TYPE, method: :global_relay_id, null: false

      field :viewer_subscription, Enums::SubscriptionState, description: "Identifies if the viewer is watching, not watching, or ignoring the subscribable entity.", null: false

      def viewer_subscription
        if @context[:viewer].nil?
          return "unsubscribed"
        end

        subscription_status_response = @object.async_subscription_status(@context[:viewer]).sync

        if subscription_status_response.failed?
          error = Platform::Errors::ServiceUnavailable.new("Subscriptions are currently unavailable. Please try again later.")
          error.ast_node = @context.irep_node.ast_node
          error.path = @context.path
          @context.errors << error
          return "unavailable"
        end

        subscription = subscription_status_response.value
        if subscription.included?
          "unsubscribed"
        elsif subscription.subscribed?
          "subscribed"
        elsif subscription.ignored?
          "ignored"
        end
      end

      field :viewer_can_subscribe, Boolean, description: "Check if the viewer is able to change their subscription status for the repository.", null: false

      def viewer_can_subscribe
        return false if @context[:viewer].nil?

        @object.async_subscription_status(@context[:viewer]).then(&:success?)
      end

      field :issues, function: Platform::Functions::Issues.new, description: "A list of issues associated with the milestone.", connection: true
      field :files, Connections.define(PackageFile), description: "List of files associated with this registry package version", null: false, connection: true
      field :enabled, Boolean, "Whether enabled for this project", method: :enabled?, null: false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-1.8.0 spec/fixtures/upgrader/subscribable.transformed.rb
graphql-1.8.0.pre11 spec/fixtures/upgrader/subscribable.transformed.rb