mll-lab / laravel-graphql-playground

This project is deprecated in favor of https://github.com/mll-lab/laravel-graphiql.
MIT License
267 stars 25 forks source link

Laravel GraphQl getting Could not connect to websocket endpoint error #53

Closed pishguy closed 3 years ago

pishguy commented 3 years ago

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 on graphql-playground:

{
  "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;
    }
}
spawnia commented 3 years ago

This package is only a thin integration layer for https://github.com/graphql/graphql-playground. This seems like it can be implemented or fixed upstream.

pishguy commented 3 years ago

@spawnia thanks, but since 1 month ago i can't resolve this problem