Copied from @alberthaff
I'm getting the same error with v. 4.0-alpha.3. The field notificationCreated is visible in GraphiQL. It seems like SubscriptionRegistry::register() is never called.
Schema:
type Subscription {
notificationCreated: Notification
}
I have created a test-command, that fires:
$data = Notification::find('dff9c576-8514-4380-9033-50fdaa4b2f8c');
Nuwave\Lighthouse\Execution\Utils\Subscription::broadcast('notificationCreated', $data);
Exception:
In Subscription.php line 36:
[InvalidArgumentException]
No subscription field registered for notificationCreated
Exception trace:
() at /Users/alberthaff/git/project/vendor/nuwave/lighthouse/src/Execution/Utils/Subscription.php:36
Nuwave\Lighthouse\Execution\Utils\Subscription::broadcast() at /Users/alberthaff/git/project/app/Console/Commands/NotifyTest.php:54
App\Console\Commands\NotifyTest->handle() at n/a:n/a
call_user_func_array() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
Illuminate\Container\BoundMethod::callBoundMethod() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
Illuminate\Container\BoundMethod::call() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Container/Container.php:572
Illuminate\Container\Container->call() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Console/Command.php:183
Illuminate\Console\Command->execute() at /Users/alberthaff/git/project/vendor/symfony/console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Console/Command.php:170
Illuminate\Console\Command->run() at /Users/alberthaff/git/project/vendor/symfony/console/Application.php:908
Symfony\Component\Console\Application->doRunCommand() at /Users/alberthaff/git/project/vendor/symfony/console/Application.php:269
Symfony\Component\Console\Application->doRun() at /Users/alberthaff/git/project/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Console/Application.php:89
Illuminate\Console\Application->run() at /Users/alberthaff/git/project/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
Illuminate\Foundation\Console\Kernel->handle() at /Users/alberthaff/git/project/artisan:35
@spawnia root cause
I suspect this is happening because as of v4, fields are no longer eagerly constructed but rather lazily loaded when needed. This results in the Subscription fields not getting registered after the initial request.
We should add a trigger to the SubscriptionServiceProvider that ensures that the fields are always registered, as subscriptions may need to be triggered even when not resolving a GraphQL request. For example when using the Subscription::broadcast() helper.
I think this also results in a 403 on the /graphql/subscriptions/auth endpoint because NuwaveLighthouseSubscriptionsSubscriptionRegistry has nothing in the $subscriptions array (which then eventually results in a NotFoundSubscription check, which fails on authentication).
What's the status of this problem? Still not fixed?
What's the status of this problem? Still not fixed?
This is a free and open-source project. You can contribute a fix.
Most helpful comment
This is a free and open-source project. You can contribute a fix.