- If you use https://github.com/accounts-js, its context may make subscription on ApolloServer fail, ref: accounts-js/accounts#565
The workaround way is
context: async (ctx: any) => {
const { req, connection } = ctx;
if (!req || !req.headers) {
return {};
}
let resp = {};
try {
resp = accountsGraphQL.context(ctx);
} catch (err) {
console.log("accountsGraphQL.context err:", err); // can not read undefind of session
}
return resp;
},
- use VSCode to launch node.js server (index.ts, pure apollo server)
yarn devin next-standalone- open http://localhost:3000 to see subscription result
OR you can
- using the VSCode 2nd launch config to launch apollo-express-erver.ts (open that file first)
yarn devin next-standalone- open http://localhost:3000 to see subscription result
OR you can
- using the VSCode 2nd launch config to launch apollo-next-server.ts (open that file first)
- open http://localhost:3000 to see subscription result
- https://www.apollographql.com/docs/react/advanced/subscriptions
- https://www.apollographql.com/docs/react/features/server-side-rendering
- https://github.com/chrizzzle/modulo
- You many need to set
import fetch from "isomorphic-unfetch"; and HttpLink({fetch:fetch)once your setting does not find out fetch - not use
import ApolloClient from "apollo-boost";useimport { ApolloClient } from 'apollo-client'/'apollo-boost'; - WebSocketLink and HttpLink use the same address:port, they even use the same path (/graphql) if ApolloServer does not specify subscriptions' path
- ApolloClient do not need to set uri
- use isomorphic-ws or process.browser? to create WebSocketLink
const WebSocket2 = require("isomorphic-ws");
const wsLink = new WebSocketLink({
webSocketImpl: WebSocket2 // browser can not use ws's WebSocket
});
or
const wsLink = process.browser
? new WebSocketLink(
new SubscriptionClient(GRAPHQL_WS_ENDPOINT, {
reconnect: true
})
)
: null;
const link = wsLink
? split(