Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async createClient(user: User, path: string) {
// Create a configuration from the user
const config = await GraphQLConfig.create(user, path, null, true);
// Construct an HTTP link that knows how to authenticate against ROS
const httpLink = concat(
config.authLink,
new HttpLink({ uri: config.httpEndpoint }),
);
// Construct a link based on WebSocket that can be used for real-time subscriptions
const webSocketLink = new WebSocketLink({
options: {
connectionParams: config.connectionParams,
},
uri: config.webSocketEndpoint,
});
// Combine the links in a way that splits based on the operation
const link = split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === "OperationDefinition" &&
max: Infinity,
retryIf: (error, _operation) => {
if (error.message === 'Network request failed') {
// if (_operation.operationName === 'createPost') {
return true;
// }
}
return false;
}
}
});
const httpLinkWithAuth = authMiddleware.concat(httpLink);
const wsLinkWithAuth = authMiddleware.concat(wsLink);
const link = concat(
retryLink,
split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLinkWithAuth,
httpLinkWithAuth
)
);
const defaultOptions = {
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all'
},