-
I tried using uWebSocket.js (port 4000) and WebSocketServer (port 5000) at server-side, both experience the same error as per the above screenshot. Any suggestions on what is wrong? (The error saying schema is not provided, but it is) Thanks a ton! Server Side codeconst mySchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: "Query",
fields: {
hello: {
type: GraphQLString,
resolve: () => "world",
},
},
}),
subscription: new GraphQLObjectType({
name: "Subscription",
fields: {
greetings: {
type: GraphQLString,
resolve: (source) => {
if (source instanceof Error) {
throw source;
}
return source.greeting;
},
subscribe: async function* () {
for (const hi of ["Hi", "Bonjour", "Hola", "Ciao", "Zdravo"]) {
yield { greetings: hi };
await new Promise((resolve) => setImmediate(resolve));
}
},
},
},
}),
});
// SERVER 1
import { WebSocketServer } from "ws";
import { useServer } from "graphql-ws/lib/use/ws";
const server = new WebSocketServer({
port: 5000,
path: "/subscriptions",
});
useServer({ mySchema }, server);
console.log("Listening to port 5000");
// SERVER 2
uWS
.App()
.ws("/subscriptions", makeBehavior({ mySchema }))
.listen(4000, (listenSocket) => {
if (listenSocket) {
console.log("Listening to port 4000");
}
}); Client Side codeimport React from "react";
import { createClient } from "graphql-ws";
const client = createClient({
url: "ws://localhost:4000/subscriptions",
//url: "ws://localhost:5000/subscriptions",
});
const MySubscription = (props) => {
client.subscribe(
{
query: "subscription { greeting }",
},
{
next: (data) => {
console.log("data", data);
},
error: (error) => {
console.error("error", error);
},
complete: () => {
console.log("no more greetings");
},
}
);
return <div>My Subscription</div>;
};
export default MySubscription; |
Beta Was this translation helpful? Give feedback.
Answered by
enisdenjo
Feb 12, 2022
Replies: 1 comment 1 reply
-
Error is self-explanatory, you're not supplying the schema. - useServer({ mySchema }, server);
+ useServer({ schema: mySchema }, server); - .ws("/subscriptions", makeBehavior({ mySchema }))
+ .ws("/subscriptions", makeBehavior({ schema: mySchema })) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
isuhendro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error is self-explanatory, you're not supplying the schema.