base_subscription.rb 1020 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Subscriptions
  3. class BaseSubscription < GraphQL::Schema::Subscription
  4. include Gql::Concern::HandlesAuthorization
  5. object_class Gql::Types::BaseObject
  6. field_class Gql::Types::BaseField
  7. argument_class Gql::Types::BaseArgument
  8. def self.field_name
  9. name.sub('Gql::Subscriptions::', '').gsub('::', '').camelize(:lower).to_sym
  10. end
  11. #
  12. # Default subscribe implementation that returns nothing. For this to work, all fields must have null: true.
  13. # Otherwise, you can provide a subscribe method in the inheriting class.
  14. #
  15. def subscribe(...)
  16. {}
  17. end
  18. def no_update
  19. # Documentation suggests to cancel updates via 'NO_UPDATE', which does not seem to work:
  20. # NameError: uninitialized constant GraphQL::Schema::Subscription::NO_UPDATE
  21. :no_update
  22. end
  23. def self.register_in_schema(schema)
  24. schema.field field_name, resolver: self
  25. end
  26. end
  27. end