Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peaceful-james opened this issue Jul 12, 2020 · 1 comment
Open

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

peaceful-james opened this issue Jul 12, 2020 · 1 comment

Comments

@peaceful-james
Copy link

peaceful-james commented Jul 12, 2020

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.

@peaceful-james
Copy link
Author

I have forked this repo and made a very naive/messy attempt to prove the problem with a test.
https://github.com/peaceful-james/absinthe_phoenix/blob/6a4ff3c7aa132acdc85a4933eda805a5ebefce2b/test/absinthe/phoenix/controller_test.exs#L163
Maybe somebody who knows what they're doing can give me some pointers? I would love to understand why these controller-sourced mutations don't trigger subscriptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant