Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
loadingComponent
}: ApolloProps) {
// add crap around mocks
const finalMocks = {
...resolvers,
Mutation: () => mutations || {},
Query: () => queries || {},
};
const schema = makeExecutableSchema({ typeDefs, resolvers: global.globalResolvers });
addMockFunctionsToSchema({
mocks: finalMocks,
schema,
});
const apolloCache = new InMemoryCache(global.__APOLLO_STATE_);
const spyLink = new SpyLink();
const graphqlClient: ApolloClient = new ApolloClient({
cache: apolloCache as any,
context,
link: ApolloLink.from([
spyLink,
new MockLink({ schema }),
]),
loadingComponent
});
graphqlClient.spyLink = spyLink;
return graphqlClient;
}
? ApolloLink.split(
hasSubscriptionOperation,
new WebSocketLink({
uri: API_WS_URL,
options: {
reconnect: true,
timeout: 50000
}
}),
http
)
: http
return new ApolloClient({
connectToDevTools: process.browser,
cache: new InMemoryCache({
fragmentMatcher,
dataIdFromObject
}).restore(initialState || {}),
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link
})
}
);
// chose the link to use based on operation
const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
httpLink
);
const client = new ApolloClient({
link: link,
cache: new InMemoryCache({
addTypename: true
})
});
return client;
};
},
});
const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
},
ws,
http,
);
apollo.create({
link,
cache: new InMemoryCache(),
});
}
}
// get the authentication token from localstorage if it exists
const token = localStorage.getItem('USER_TOKEN')
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
Authorization: token ? `Bearer ${token}` : ''
}
}
})
// Create the apollo client
const apolloClient = new ApolloClient({
link: httpLinkAuth.concat(httpLink),
cache: new InMemoryCache()
})
// Install the vue plugin
Vue.use(VueApollo)
const apolloProvider = new VueApollo({
defaultClient: apolloClient
})
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
localStorage.getItem('USER_TOKEN') ? next() : next('/login')
} else {
next()
}
})
Vue.prototype.$http = axios;
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: "ko",
fallbackLocale: "en",
messages,
silentTranslationWarn: true
});
const link = new HttpLink({
uri: `http://localhost:4000/graphql`
});
const apolloClient = new ApolloClient({
link,
cache: new InMemoryCache(),
connectToDevTools: true
});
const apolloProvider = new VueApollo({
defaultClient: apolloClient
});
Vue.use(VueApollo);
Vue.use(BootstrapVue);
new Vue({
el: "#app",
router,
store,
i18n,
apolloProvider,
render: h => h(App)
});
cache() {
const cache = new InMemoryCache({
dataIdFromObject,
freezeResults: false
});
const cachedContent = this.shoebox.read(
config.apollo.SSR_CACHE_KEY
) as NormalizedCacheObject;
if (!cachedContent) return cache;
return cache.restore(cachedContent);
}
});
if (cookies && Object.keys(cookies).length) {
const middlewareLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
Cookie: Object.keys(cookies)
.map((key) => `${key}=${cookies[key]}`)
.join('; '),
},
});
return forward!(operation);
});
link = middlewareLink.concat(link);
}
const cache = new InMemoryCache(cacheOpts);
if (initialData) {
cache.restore(initialData);
}
if (linkState) {
link = ApolloLink.from([link, linkState]);
}
return new ApolloClient({
link,
cache,
ssrMode: true,
...opts,
});
};
} from 'apollo-cache-inmemory';
import { persistCache } from 'apollo-cache-persist';
import { MuiThemeProvider, withStyles } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import storage from 'localforage';
import theme from '../theme';
import FontStager from '../components/FontStager/index';
import ErrorPanel from '../components/ErrorPanel/index';
import routes from './routes';
import introspectionQueryResultData from '../fragmentTypes.json';
import Spinner from '../components/Spinner';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
});
const cache = new InMemoryCache({ fragmentMatcher });
persistCache({
cache,
storage,
});
@hot(module)
@withStyles({
'@global': {
a: {
color: theme.palette.secondary.dark,
},
},
spinner: {
marginTop: 60,
},