//file: apolloClient.js
import { Client } from 'subscriptions-transport-ws';
import addGraphQLSubscriptions from './helpers/subscriptions';
const wsClient = new Client('ws://localhost:8080');
const networkInterface = createNetworkInterface({
uri:'/api',
// opts: {
// credentials: 'same-origin',
// },
// transportBatching: true,
})
networkInterface.use([authMiddleware])
networkInterface.useAfter([authAfterware, logErrorsAfterware]);
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient,
);
const client = new ApolloClient({
// networkInterface,
networkInterface: networkInterfaceWithSubscriptions,
batchInterval: 10,
queryDeduplication: true,
queryTransformer: addTypename,
dataIdFromObject: (result) => result.id || null
})
//file: ./helpers/subscriptions.js
import { print } from 'graphql-tag/printer';
// quick way to add the subscribe and unsubscribe functions to the network interface
const addGraphQLSubscriptions = (networkInterface, wsClient) => Object.assign(networkInterface, {
subscribe: (request, handler) => wsClient.subscribe({
query: print(request.query),
variables: request.variables,
}, handler),
unsubscribe: (id) => {
wsClient.unsubscribe(id);
},
});
export default addGraphQLSubscriptions;
Getting Uncaught Error: Cannot find module "../package.json"
Uncaught Error: Cannot find module "../package.json"
at bundle.e0afedc….js:40432
at Object.<anonymous> (bundle.e0afedc….js:40432)
at t (bundle.e0afedc….js:1)
at Object.<anonymous> (bundle.e0afedc….js:40432)
at t (bundle.e0afedc….js:1)
at Object.<anonymous> (bundle.e0afedc….js:40432)
at t (bundle.e0afedc….js:1)
at Object.<anonymous> (bundle.e0afedc….js:40432)
at t (bundle.e0afedc….js:1)
at Object.<anonymous> (bundle.e0afedc….js:40432)
yarn add subscriptions-transport-ws
yarn build // i use webpack to bundle my app
as soon as I bundle the app and try to load my page, I start getting this error. anything obvious i'm missing?