How can I add my subscription handler function with hydrate?

I use an SDL schema and I try to use hydrate to add resolver functions to my queries, mutations and
subscriptions. Queries and mutations work fine, but for some reasons subscriptions do not.

This is how my resolve function looks like:

def hydrate(%Absinthe.Blueprint{}, _) do
    mutation: [%{my_mutation: [resolve: &SomeModule.resolve_my_mutation/3]}],
    query: [%{my_query: [resolve: &SomeModule.resolve_my_query/3]}],
    subscription: [%{my_subscription: [resolve: &SomeModule.resolve_my_subscription/3]}]

The resolve_my_mutation/3 and resolve_my_query/3 is called when a mutation or query is executed, but resolve_my_subscription/3 isn’t called ever.

What am I doing wrong here with subscriptions?

Hey @sandorbedo the resolver in a subscription is called when the subscription is executed from a publish, not when the subscription is submitted. How are you testing the subscription?

Hmm. There has to be a function that determines the topic string, when the subscription is submitted. I thought it is the resolver of the subscription, but I guess I’m wrong. This function is called config in Absinthe’s own schema language, and returns something like {:ok, topic: "topic:123"}. How can I add this config function to my SDL schema with hydrate/2 ?

Yeah that isn’t the resolver, that’s the config function. I believe you simply do my_subscription [config: &your_config_function/3].

It doesn’t work. I tried [config: &SomeModule.subs/3] and also subs/2, since the config function used to be 2-arity in the Absinthe schema, but does not work for me:

** (ArgumentError) Invalid hydration!

{:config, &SomeModule.subs/2}

is not a valid way to hydrate

In the source code of Absinthe.Phase.Schema.Hydrate.apply_hydration/3 it seems like only the following options are accepted:

  • {:meta, keyword_list}
  • {:description, text}
  • {:resolve, resolver}
  • {:middleware, {_module, _opts} = middleware}
  • {:complexity, complexity}
  • {:parse, parse}
  • {:serialize, serialize}
  • {:resolve_type, resolve_type}
  • {:is_type_of, is_type_of}
  • {:as, value}

There’s no :config or anything similar here. :frowning:

Will review, this may be an oversight on my end. Please make an issue on the Absinthe repo if you have a moment.