The Apollo docs say to use:
import { SubscriptionManager } from 'graphql-subscriptions';
…and provide the following code for getting subscriptions running on the server:
import { SubscriptionManager } from 'graphql-subscriptions';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { createApolloServer, addCurrentUserToContext } from 'meteor/apollo';
// your executable schema
const schema = ...
// any additional context you use for your resolvers, if any
const context = {};
// the pubsub mechanism of your choice, for instance:
// - PubSub from graphql-subscriptions (not recommended for production)
// - RedisPubSub from graphql-redis-subscriptions
// - MQTTPubSub from graphql-mqtt-subscriptions
const pubsub = new PubSub();
// subscriptions path which fits witht the one you connect to on the client
const subscriptionsPath = '/subscriptions';
// start a graphql server with Express handling a possible Meteor current user
createApolloServer({
schema,
context
});
// create the subscription manager thanks to the schema & the pubsub mechanism
const subscriptionManager = new SubscriptionManager({
schema,
pubsub,
});
// start up a subscription server
new SubscriptionServer(
{
subscriptionManager,
// on connect subscription lifecycle event
onConnect: async (connectionParams, webSocket) => {
// if a meteor login token is passed to the connection params from the client,
// add the current user to the subscription context
const subscriptionContext = connectionParams.meteorLoginToken
? await addCurrentUserToContext(context, connectionParams.meteorLoginToken)
: context;
return subscriptionContext;
},
},
{
// bind the subscription server to Meteor WebApp
server: WebApp.httpServer,
path: subscriptionsPath,
}
);
When running this code, the console log shows:
subscriptionManager is deprecated, use
execute
orsubscribe
directly fromgraphql-js
!
Is there sample code showing how to use execute
or subscribe
directly from graphql-js
?
A link would be greatly appreciated!