Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
export const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
wsLink,
httpLink,
);
// Instantiate client
export const client = new ApolloClient({
link,
uri: GRAPHQL_URI,
cache: new InMemoryCache()
})
return result.__typename + result.id; // eslint-disable-line no-underscore-dangle
}
return null;
},
networkInterface,
};
if (__CLIENT__) {
if (window.__APOLLO_STATE__) {
params.initialState = window.__APOLLO_STATE__;
}
params.ssrForceFetchDelay = 100;
} else {
params.ssrMode = true;
}
return new ApolloClient(params);
};
import config from '../config';
import UI from './UI';
import Auth from './Auth';
if (__DEV__) { // eslint-disable-line
const nativeXMLHttpRequest = XMLHttpRequest; // eslint-disable-line
const devXMLHttpRequest = GLOBAL.originalXMLHttpRequest ? GLOBAL.originalXMLHttpRequest : GLOBAL.XMLHttpRequest; // eslint-disable-line
GLOBAL.XMLHttpRequest = devXMLHttpRequest;
}
// Create new Apollo client
const link = new Link({
uri: config.GRAPHQL_ENDPOINT,
});
const cache = new InMemoryCache();
const client = new ApolloClient({
link,
cache,
});
export default class Store {
client = client;
ui = new UI();
auth = new Auth();
async setup() {
return true;
}
}
export class StoreProvider extends PureComponent {
it('renders correctly', () => {
const query = gql`query people { allPeople(first: 1) { people { name } } }`;
const data = { allPeople: { people: { name: 'Luke Skywalker' } } };
const networkInterface = mockNetworkInterface({ request: { query }, result: { data } });
const client = new ApolloClient({ networkInterface });
const ContainerWithData = graphql(query)(({ data }) => {
if (data.loading) return
return ;
});
const output = renderer.create(
)
expect(output.toJSON()).toMatchSnapshot();
});
cache.writeData({
data: {
token: null
}
});
Cookies.remove('token');
Router.push('/');
}
})
const link = createHttpLink({
uri: host,
fetch: fetch,
credentials: 'same-origin'
})
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser,
link: authLink.concat(errorLink).concat(link),
cache,
resolvers
});
}
const createClient = req => {
return new ApolloClient({
ssrMode: true,
link: ApolloLink.from([
createOmitTypenameLink(),
createHttpLink({
uri: process.env.REACT_APP_API_HOST + "/function/api",
credentials: "same-origin",
headers: {
cookie: req.header("Cookie")
}
})
]),
cache: new InMemoryCache({
addTypename: true,
dataIdFromObject: obj => obj.id || null
})
});
const Client = () => {
const networkInterface = createNetworkInterface({
uri: 'http://localhost:8080/graphql'
})
const client = new ApolloClient({
networkInterface
});
return (
)
}
new RetryLink({
delay: {
initial: 300,
max: Infinity,
jitter: true,
},
attempts: {
max: 3,
retryIf: (error, _operation) => !!error,
},
}),
wsLink,
]);
this.resolver(
new ApolloClient({
link,
cache,
defaultOptions: {
query: {
fetchPolicy: 'cache-and-network',
},
},
}),
);
}
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {};
}
req.options.headers.authorization = localStorage.getItem(config.authTokenName);
next();
}
}]);
const host = location.origin.replace(/^http/, 'ws');
const wsClient = new Client(host);
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(networkInterface, wsClient);
const client = new ApolloClient({
networkInterface: networkInterfaceWithSubscriptions,
dataIdFromObject: (result) => {
if (result.id && result.__typename) {
return result.__typename + result.id;
}
return null;
},
shouldBatch: true,
initialState: window.__APOLLO_STATE__,
ssrForceFetchDelay: 100,
});
const initialState = window.__INITIAL_STATE__;
const store = configureStore({ initialState, client });
function render() {
const createClient = headers => {
return new ApolloClient({
ssrMode: !process.browser,
headers,
dataIdFromObject: result => result.id || null,
networkInterface
})
}