Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const local = withClientState({
resolvers: {
Bar: {
bar: () => 'Bar',
},
Baz: {
baz: () => 'Baz',
},
},
fragmentMatcher: ({ __typename }, typeCondition) =>
__typename === typeCondition,
});
const client = new ApolloClient({
cache: new InMemoryCache({
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'UnionTypeDefinition',
name: 'Foo',
possibleTypes: [{ name: 'Bar' }, { name: 'Baz' }],
},
],
},
},
}),
}),
link: local.concat(link),
});
//@flow
import {ApolloClient} from 'apollo-client';
import {createHttpLink} from 'apollo-link-http';
import {InMemoryCache, IntrospectionFragmentMatcher} from 'apollo-cache-inmemory';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'UNION',
name: 'QueryResult',
possibleTypes: [{name: 'queryError'}, {name: 'results'}],
},
],
},
},
});
type Options = {
port: number,
};
createFragmentMatcher() {
if (global['APOLLO_FRAGMENT_TYPES']) {
return new IntrospectionFragmentMatcher({
introspectionQueryResultData: global['APOLLO_FRAGMENT_TYPES'],
});
}
return new HeuristicFragmentMatcher();
}
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
import produce from 'immer';
import VueApollo from 'vue-apollo';
import getIssueStateQuery from '~/issue_show/queries/get_issue_state.query.graphql';
import createDefaultClient from '~/lib/graphql';
import introspectionQueryResultData from './fragmentTypes.json';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
});
const resolvers = {
Mutation: {
updateIssueState: (_, { issueType = undefined, isDirty = false }, { cache }) => {
const sourceData = cache.readQuery({ query: getIssueStateQuery });
const data = produce(sourceData, (draftData) => {
draftData.issueState = { issueType, isDirty };
});
cache.writeQuery({ query: getIssueStateQuery, data });
},
},
};
export const defaultClient = createDefaultClient(resolvers, {
global.fetch = fetch
}
export const dataIdFromObject = object => {
if (object.__typename) {
if (object.id !== undefined) {
return `${object.__typename}:${object.id}`
}
if (object._id !== undefined) {
return `${object.__typename}:${object._id}`
}
}
return null
}
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'UNION',
name: 'Reward',
possibleTypes: [
{
name: 'Goodie'
},
{
name: 'MembershipType'
}
]
},
{
import mount from 'react/util/mount';
import { Themed } from 'react/styles/theme';
import introspectionQueryResultData from 'react/apollo/fragmentTypes.json';
import clientData from 'react/apollo/localState/clientData';
const isClientSide = typeof window !== 'undefined';
const { data: { GRAPHQL_ENDPOINT, CLIENT_GRAPHQL_ENDPOINT } } = sharify;
const clientHttpLink = new BatchHttpLink({ uri: CLIENT_GRAPHQL_ENDPOINT });
const serverHttpLink = new BatchHttpLink({ uri: GRAPHQL_ENDPOINT });
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
});
export const initApolloClient = ({
token: X_AUTH_TOKEN,
currentRoute,
isLoggedIn,
cookies,
serializedMe,
sharifyData,
} = {}) => {
if (isClientSide && window.__APOLLO_CLIENT__) {
return window.__APOLLO_CLIENT__;
}
const cache = new InMemoryCache({ fragmentMatcher });
createFragmentMatcher() {
return !introspectionResult
? new HeuristicFragmentMatcher()
: new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionResult,
});
}
createFragmentMatcher() {
return !introspectionResult
? new HeuristicFragmentMatcher()
: new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionResult,
});
}