Rails 5.1.4
grapqhl -1.7.5
ruby 2.4.1
I'm trying to setup a subscription with arguments -
I'm loading this into the Subscription Schema
Subscriptions::SimpleSaleWentStaleSubscription = GraphQL::ObjectType.define do
name "SimpleSaleWentStale"
field :staleSimpleSale, !Types::SimpleSaleType do
argument :simpleSaleId, types.ID
end
end
on my client - Apollo 2 over ActionCable
If I make a request like -
subscription simpleSaleWentStale {
simpleSaleWentStale{
id
transactionNumber
stale
}
}
I can do a trigger with or without the id and the client gets the update. I wants clients to only get updates for things they have actually seen. I modified the the query to be like -
subscription simpleSaleWentStale($simpleSaleId: ID) {
simpleSaleWentStale(simpleSaleId: $simpleSaleId){
id
transactionNumber
stale
}
}
When I do that the client never gets a subscription id set in the context. No errors are displayed - it just silently ignores the subscription request. Is this a know issue? Any recommendations on where i look?
Hi!
simpleSaleWentStale(simpleSaleId: $simpleSaleId)
This looks like a good way to subscribe to a single sale. Can you share the code for your .trigger call in that case? It should have { simpleSaleId: sale.id } so that the arguments to .trigger match the GraphQL arguments.
First -thanks for the super fast response! Second - is the sale.id supposed to be raw Ruby id or the graphql encoded version?
good question, I think it should match the value of $simpleSaleId, so it should be the graphql encoded version
Ok so this turned out to be a combination of how I setup the subscription type - and the trigger statement. The id in the variables section does have to be the graphql encoded version. It appears that the key has to be a string and not a symbol :)
It was also helpful once I realized - action cable swallows errors from the grapqhl - I added this:
result = SimpleSaleSchema.execute({
query: query,
context: context,
variables: variables,
operation_name: operation_name
})
if result.to_h["errors"]
logger.error "Errors #{result.to_h["errors"].inspect}"
end
And I could finally see that things weren't matching up. Thanks again for being responsive. You gave me confidence that I was close - so it just took me some time to get it all wired up.
Most helpful comment
Ok so this turned out to be a combination of how I setup the subscription type - and the trigger statement. The id in the variables section does have to be the graphql encoded version. It appears that the key has to be a string and not a symbol :)
It was also helpful once I realized - action cable swallows errors from the grapqhl - I added this:
result = SimpleSaleSchema.execute({
query: query,
context: context,
variables: variables,
operation_name: operation_name
})
if result.to_h["errors"]
logger.error "Errors #{result.to_h["errors"].inspect}"
end
And I could finally see that things weren't matching up. Thanks again for being responsive. You gave me confidence that I was close - so it just took me some time to get it all wired up.