4

I trying to figure out how to correctly define subscriptions in my schema using graphene-python. So far I have implemented queries and mutations, but how do you define a Subscription class?

Below is what I was originally thinking:

class Subscription(graphene.Subscription):
  name = graphene.String()
  # rest of attributes...

  def subscribe(self, args, context, info):
    pass

Can someone please provide a small example? Any help would be greatly appreciated! Thank you :).

Brian

Brian
  • 421
  • 3
  • 20
  • 1
    I believe I have figured it out. Once I am comfortable with the code, I will post back here. – Brian Jun 30 '17 at 17:32

1 Answers1

2

So after some trial and error, the following code below will work for subscriptions. Essentially a subscription can be treated the same as a query.

class Subscription(graphene.ObjectType):
  # Define subscription attributes, i.e. what you want the user to subscribe to.
  # This part will most likely be defined by your schema.
  subscription_attr = graphene.Int()

  def resolve_events_count(self, args, context, info):
    ## define resolver function once UI provides subscription data...
    return 'Value here defined as graphene class'
Brian
  • 421
  • 3
  • 20