Skip to content

Controller-based mutations don't "trigger" subscriptions #74

@peaceful-james

Description

@peaceful-james

I can expand on this as much as you want so I'll just put down the basic info for now.

If I have a mutation in a phoenix controller (in a @graphql module attribute), like this:

  @graphql """
  mutation UpdateMenuItem($id: ID!, $description: String!) {
  update_menu_item(id: $id, input: {description: $description}) {
    errors { key message }
    menu_item {
      name
      description
    }
    }
  }
  """
  def update(conn, %{data: %{update_menu_item: %{errors: nil, menu_item: menu_item}}}) do
    # ... controller update logic here, conn |> redirect or whatever
  end

And if this mutation is meant to trigger a subscription, for example if my schema.ex is like this:

subscription do
    field :updated_menu_item, :menu_item do
      config(fn _args, _info ->
        {:ok, topic: "*"}
      end)

      trigger(:update_menu_item,
        topic: fn
          %{menu_item: menu_item} -> ["*"]
          _ -> []
        end
      )

      resolve(fn %{menu_item: menu_item}, _, _ ->
        {:ok, menu_item}
      end)
    end

# more subscriptions,etc.
end

then the subscription is not triggered. This might have something to do with how the Absinthe.Phoenix SDL is processed differently to normal Graphql SDL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions