5

After implementing a simple GraphQl query such as a simple Mutation and Subscription I get this error when I try to run this subscription into graphql-playground:

subscription {
   userCreated{
     name
     username
     password
   }
}

I get this error:

{
  "error": "Could not connect to websocket endpoint ws://127.0.0.1:8000/graphql. 
Please check if the endpoint url is correct."
}

GraphQl Schema:

#...
type User {
    id: Int!
    name: String
    email: String
    product : [Product!]
}

type Mutation {
 createUser(
    name: String!
    password: String!
    email : String!
  ): User @field(resolver:"UserMutator@create") @broadcast(subscription: "userCreated")
}

type Subscription {
  userCreated: User
}

UserMutator class:

class UserMutator{
    public function create($_ , array $args){
        $user =  User::create($args);
        Subscription::broadcast('userCreated',$user);
        //return $user;
    }

UserCreated Subscription

class UserCreated extends GraphQLSubscription
{
    public function authorize(Subscriber $subscriber, Request $request): bool
    {
          return true;
    }

    public function filter(Subscriber $subscriber, $root): bool
    {
        return true;
    }
}
DolDurma
  • 15,753
  • 51
  • 198
  • 377

0 Answers0