Closed ristiisa closed 2 years ago
I'm pretty sure that you are using the wrong protocol, but without code is hard to reproduce!
Waiting for code to reproduce it
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';
import { WebSocketServer } from 'ws';
import { useServer } from 'graphql-ws/lib/use/ws';
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
type: GraphQLString,
resolve: () => 'world',
},
},
}),
subscription: new GraphQLObjectType({
name: 'Subscription',
fields: {
greetings: {
type: GraphQLString,
subscribe: async function* () {
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
yield { greetings: hi };
}
}
}
}
})
});
const server = new WebSocketServer({
port: 4000,
path: '/graphql',
});
useServer({ schema }, server);
console.log('Listening to port 4000');
ws_test() {
var client = GraphQLClient(
cache: GraphQLCache(partialDataPolicy: PartialDataCachePolicy.accept),
defaultPolicies: DefaultPolicies(
query: Policies.safe(
FetchPolicy.noCache,
ErrorPolicy.none,
CacheRereadPolicy.mergeOptimistic,
),
subscribe: Policies.safe(
FetchPolicy.noCache,
ErrorPolicy.none,
CacheRereadPolicy.mergeOptimistic,
),
mutate: Policies.safe(
FetchPolicy.noCache,
ErrorPolicy.none,
CacheRereadPolicy.mergeOptimistic,
),
watchMutation: Policies.safe(
FetchPolicy.noCache,
ErrorPolicy.none,
CacheRereadPolicy.mergeOptimistic,
),
watchQuery: Policies.safe(
FetchPolicy.noCache,
ErrorPolicy.none,
CacheRereadPolicy.mergeOptimistic,
)
),
link: WebSocketLink("ws://localhost:4000/graphql", subProtocol: GraphQLProtocol.graphqlTransportWs),
).subscribe(SubscriptionOptions(
document: gql("subscription { greeting }"),
)).listen((event) {
print(event.data);
})
..onError((error, stack) {
print([error, stack]);
})
..onDone(() => print("done"));
}
what protocol graphql-ws has?
graphql-transport-ws
req:
rsp:
GraphQLSocketMessage.parse seems to throw when server responds to a subscription with an error
message:
Flutter (Channel stable, 3.3.3, on macOS 11.6.2 20G314 darwin-x64, locale en-EE)
graphql: ^5.1.2-beta.4
backend side: