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.
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.
I've created a repo for this issue based off absinthe-tutorial: https://github.com/davidye/absinthe_tutorial
subscription {
roomUpdated(name:"absinthe") {
name
random
}
}
5) Run this mutation
mutation {
updateRoom(name:"absinthe") {
name
random
}
}
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
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
鉂わ笍 馃挌 馃挋 馃挍
Most helpful comment
See https://github.com/absinthe-graphql/absinthe/pull/529