-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Allow passing through the rootValue as an option #492
Conversation
@tuurbo nice, never heard of it Can you share some use cases and add a test for it, please? |
Here is a use case I currently use. // NotificationMutation.php
$notification = Notification::find($id);
$notification->whatever = 'foobar';
$notification->save();
// send to clients via redis pub/sub
$this->publish('notification', $notification->fresh()); function publish($subscriptionName, $rootValue) {
// check if anyone is subscribing to the $subscriptionName
$subscription = $this->getSubscription($subscriptionName);
if ($subscription) {
// retrieve the schema of the $subscription
$schema = $this->getSchema($subscription);
// parse $rootValue into a graphql payload
$payload = \GraphQL::query($schema, [], ['rootValue' => $rootValue]);
// send payload to anyone subscribed to the schema that macthes the $subscriptionName
Redis::connection('pub')->publish('graphql-channel', json_encode([
'type' => 'data',
'id' => $subscription['id'],
'payload' => $payload,
'key' => $subscription['key'],
]));
}
} |
@mfn Submitted use case and test, Thanks |
doing graphql subscriptions here? If yes maybe you could care to share som code, would be could to add support for it in the framework |
Sorry, totally forgot about this PR 🤷♀️ I've added a changelog and squashed the commits and released it with https://github.com/rebing/graphql-laravel/releases/tag/3.1.0 |
@tuurbo do you remember why you used I'm in the process of revamping the internal working and wonder if we truly need to support the |
@mfn Its been a while since I've looked at this but we still use the code I wrote above today. I remember copying the apollo graphql JS library and rewriting it into php to suit our needs. https://github.com/apollographql/graphql-subscriptions/blob/v0.1.5/src/pubsub.ts#L155-L156 Not sure if the recommended way it's done now is any different. Passing the data as context seems weird to me but I suppose it would work. I don't know enough about the inner workings of graphql to say for sure. |
@tuurbo thanks for your quick response, I found out I don't need to remove support for it |
As seen in https://github.com/webonyx/graphql-php/blob/master/docs/executing-queries.md