Подписка, кажется, отвечает, но без значения.
Запрос:
const query = `subscription {
info {
__typename
}
}`;
И ответ:
received data: {
"data": {
"info": null
}
}
complete
Ответ поступает от следующего обработчика в коде клиента (внизу).Вот краткий обзор кода сервера и клиента:
Сервер:
import { ApolloServer } from 'apollo-server-express';
import fetch from 'node-fetch';
import { execute} from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import gql from 'graphql-tag';
/*
typedefs = {
...
union Info = Score | Depth | Nps | BestMove
...
type Subscription {
info: Info
}
...
}
*/
/*
resolvers = {
...
Info: {
__resolveType(obj, context, info) {
console.log('called'); // this never appears
return 'Score';
},
},
...
Subscription: {
info: {
subscribe: withFilter(() => pubsub.asyncIterator(TOPIC), (payload, variables) => true),
},
},
}
*/
const server = new ApolloServer({
typeDefs,
resolvers,
});
Клиент
const link = new HttpLink({ uri, fetch });
const subscribe = (query, handlers) => {
const operation = {
query: gql`${query}`,
};
return execute(link, operation).subscribe(handlers);
};
export default doQuery;
export { subscribe };
const query = `subscription {
info {
__typename
}
}`;
// const res = await fetch(query).data;
const handlers = {
next: data => console.log(`received data: ${JSON.stringify(data, null, 2)}`),
error: error => console.log(`received error ${error}`),
complete: () => console.log('complete'),
};
subscribe(query, handlers);