Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// To debug queries add print(req.request.query) and import it from graphql/language/printer
// console.log(print(req.request.query));
next();
},
},
]);
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient
);
const client = new ApolloClient({
connectToDevTools: true,
addTypename: true,
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionData,
}),
dataIdFromObject: result => {
if (result.id && result.__typename) {
// eslint-disable-line no-underscore-dangle
return `${result.__typename}_${result.id}`; // eslint-disable-line no-underscore-dangle
}
return null;
},
networkInterface: networkInterfaceWithSubscriptions,
});
client.resetWebsocket = () => {
if (wsClient.client) {
// Close socket connection which will also unregister subscriptions on the server-side.
wsClient.close(true);
import {IntrospectionFragmentMatcher} from 'apollo-client';
// TODO this is a short-term fix
// we need to set up something to query the server for the schema before ApolloClient initialization
// https://github.com/apollographql/apollo-client/issues/1555#issuecomment-295834774
const fm = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'INTERFACE',
name: 'UserError',
possibleTypes: [
{name: 'GenericUserError'},
{name: 'ValidationUserError'}
]
},
{
kind: 'INTERFACE',
name: 'Response',
possibleTypes: [
{name: 'CreateCommentResponse'},
uri: requestUri,
});
// Use persisted queries and GET requests in production.
const finalNetworkInterface =
isProduction && hasApiVersion
? addGetRequests(
addPersistedQueries(apiVersion, queryMap, networkInterface),
)
: networkInterface;
const apolloClient = new ApolloClient({
reduxRootSelector: state => state.apollo,
networkInterface: finalNetworkInterface,
ssrMode: __SERVER__,
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionData,
}),
});
return apolloClient;
};
uri: requestUri,
});
// Use persisted queries and GET requests in production.
const finalNetworkInterface =
isProduction && hasApiVersion
? addGetRequests(
addPersistedQueries(apiVersion, queryMap, networkInterface),
)
: networkInterface;
const apolloClient = new ApolloClient({
reduxRootSelector: state => state.apollo,
networkInterface: finalNetworkInterface,
ssrMode: __SERVER__,
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionData,
}),
});
return apolloClient;
};
if (!req.options.headers) {
req.options.headers = {};
}
const token = await Auth.getToken();
req.options.headers.authorization = token;
next();
},
}]);
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient,
);
const feedFragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'INTERFACE',
name: 'Feed',
possibleTypes: [
{
name: 'GroupFeed',
},
{
name: 'TripFeed',
},
{
name: 'CommentFeed',
},
connectionParams: () => {
if (!AuthorizationMiddleware.token || AuthorizationMiddleware.token === '') {
return {};
}
return {'player-token': AuthorizationMiddleware.token};
},
connectionCallback: (error => {
if (error) {
AuthorizationMiddleware.setToken('');
window.location.href = '/';
}
})
});
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
'kind': 'INTERFACE',
'name': 'User',
'possibleTypes': [
{'name': 'Player'},
{'name': 'Viewer'}
]
},
],
},
}
});