Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
// Retry mutations for a looong time, those are very important to us so we want them to go through eventually
if (isMutation) {
return !!error && count < 25;
}
// Retry queries for way less long as this just ends up showing
// loading indicators for that whole time which is v annoying
return !!error && count < 6;
},
});
// HTTP Link for queries and mutations including file uploads
const httpLink = retryLink.concat(
createUploadLink({
uri: API_URI,
credentials: 'include',
headers,
})
);
// Switch between the two links based on operation
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink
);
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient } from "apollo-client";
import { createUploadLink } from "apollo-upload-client";
import { GQL_URI } from "./constants";
const cache = new InMemoryCache();
export const apolloClient = new ApolloClient({
cache,
// createUploadLink handles the file upload
link: createUploadLink({
uri: GQL_URI,
credentials: "include"
})
});
typeDefs = undefined,
// Local Resolvers
resolvers = undefined,
// Hook called when you should write local state in the cache
onCacheInit = undefined,
}) {
let wsClient, authLink, stateLink
const disableHttp = websocketsOnly && !ssr && wsEndpoint
// Apollo cache
if (!cache) {
cache = new InMemoryCache(inMemoryCacheOptions)
}
if (!disableHttp) {
const httpLink = createUploadLink({
uri: httpEndpoint,
...httpLinkOptions,
})
if (!link) {
link = httpLink
} else if (defaultHttpLink) {
link = from([link, httpLink])
}
// HTTP Auth header injection
authLink = setContext((_, { headers }) => {
const authorization = getAuth(tokenName)
const authorizationHeader = authorization ? { authorization } : {}
return {
headers: {
export const createApolloClient = (apiUrl, websocketApiUrl) => {
const cache = new InMemoryCache();
const errorLink = handleErrors();
const authLink = createAuthLink();
const uploadLink = createUploadLink({ uri: apiUrl }); // Upload link also creates an HTTP link
// Create WebSocket link
const authToken = localStorage.getItem('token');
const wsLink = new WebSocketLink({
uri: websocketApiUrl,
options: {
timeout: 60000,
reconnect: true,
connectionParams: {
authorization: authToken,
},
},
});
// Temporary fix for early websocket closure resulting in websocket connections not being instantiated
// https://github.com/apollographql/subscriptions-transport-ws/issues/377
function create(initialState, { getToken }) {
let httpLink = createUploadLink({
uri: `${envs.serverURL()}/graphql`,
credentials: 'include'
})
const authLink = setContext((operation, inData) => {
const { headers } = inData
const token = getToken()
console.log('token', token)
console.log('operation', operation)
if (token) {
return operation[
{
headers: {
...headers,
Cookie: token ? token : null
}
}
export default uri =>
ApolloLink.split(
({ variables }) => extractFiles(cloneDeep(variables)).length > 0,
createUploadLink({ uri, credentials: 'include' }),
new BatchHttpLink({
uri,
credentials: 'include'
})
);
import { ApolloClient } from "apollo-client";
import { InMemoryCache } from "apollo-cache-inmemory";
import { createUploadLink } from "apollo-upload-client";
import { Platform } from "react-native";
const host =
Platform.OS === "ios" ? "http://localhost:4000" : "http://10.0.2.2:4000";
export const client = new ApolloClient({
link: createUploadLink({
uri: host
}),
cache: new InMemoryCache()
});
const createApolloClient = (cache = {}) =>
new ApolloClient({
ssrMode: typeof window !== 'undefined',
cache: new InMemoryCache().restore(cache),
link: createUploadLink({ uri: process.env.API_URI })
})
import './index.css'
import Gooseberries from './Gooseberries'
import * as serviceWorker from './serviceWorker'
import { AUTH_TOKEN } from './constants'
import defaults from './graphql/defaults'
import resolvers from './graphql/resolvers'
const cache = new InMemoryCache()
const stateLink = withClientState({
resolvers,
cache,
defaults
})
const httpLink = createUploadLink({
uri: 'http://localhost:8000/graphql'
})
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem(AUTH_TOKEN)
return {
headers: {
...headers,
authorization: token ? `JWT ${token}` : ''
}
}
})
const client = new ApolloClient({
link: ApolloLink.from([stateLink, authLink.concat(httpLink)]),
cache: cache
const httpLink = (() => {
const config = {
uri: API_URL,
credentials: 'same-origin'
};
if (ENABLE_UPLOADS) {
return createUploadLink(config);
}
return createHttpLink(config);
})();