Absinthe: Subscription documents resolve based on incorrect context

Created on 19 Mar 2018  路  8Comments  路  Source: absinthe-graphql/absinthe

Environment

  • Elixir version (elixir -v): 1.6.2
  • Absinthe version (mix deps | grep absinthe): 1.4.9
  • Client Framework and version (Relay, Apollo, etc): Relay

Expected behavior

My schema has a room node that contains a user field. This field resolves to the current user based on context.user_id.

When multiple clients with unique context.user_id values subscribe to a room_update subscription, and a mutation triggers the subscription publication, each client should receive a different value for the user field.

Actual behavior

Each client receives the same value for the user field. When logging the context in the user field resolver, context.user_id is the same for each client.

Note: In the case where the subscription is published to only one client, the user field does resolve correctly.

Most helpful comment

All 8 comments

I've created a repo for this issue based off absinthe-tutorial: https://github.com/davidye/absinthe_tutorial

Steps

  1. Run the app and load http://localhost:4000/api/graphiql
  2. Set URL as http://localhost:4000/api
  3. Set WS URL as ws://localhost:4000/socket
  4. Run two or more subscriptions
subscription {
  roomUpdated(name:"absinthe") {
    name
    random
  }
}

5) Run this mutation

mutation {
  updateRoom(name:"absinthe") {
    name
    random
  }
}

Expected

Each subscription is assigned a random value in its context: https://github.com/davidye/absinthe_tutorial/blob/master/lib/blog_web/channels/user_socket.ex#L24-L26

Room query resolves room.random from context: https://github.com/davidye/absinthe_tutorial/blob/master/lib/blog_web/resolvers/rooms.ex#L11-L16

When the mutation is run, each subscription should return a different value for roomUpdated.random

Actual

When the mutation is run, each subscription receives the same value for roomUpdated.random

Thanks for the example, I've confirmed the issue and am investigating now.

Seems like the issue is in BatchResolver, I was able to fix it locally by setting this line: https://github.com/absinthe-graphql/absinthe/blob/266728e8a78c6d2fb6f14bf03740e92b2c393e99/lib/absinthe/pipeline/batch_resolver.ex#L21 to

  context: nil

And removing references to ctx in that file.

Yeah, this is a product of an effort to try to get dataloader to work across multiple document sets. In the short term I think I can go one step up and group the documents by those with equivalent contexts, and then pass those groups in to the batch resolver one at a time. This should prevent contexts from leaking.

This issue is affecting us too, currently blocking a feature we need. LMK if there's anything I can do to help :)

Fixed in Absinthe v1.4.10

鉂わ笍 馃挌 馃挋 馃挍

Was this page helpful?
0 / 5 - 0 ratings