Add graph-handling for different environments
This commit is contained in:
@@ -1,10 +1,36 @@
|
||||
const queryString = require('query-string');
|
||||
const { createApolloFetch } = require('apollo-fetch');
|
||||
const { includeCredentials } = require('./middleware');
|
||||
|
||||
const defaultGraphUri = '/graph';
|
||||
const defaultGraphUri = 'https://dancefinder.unbound.se/graph';
|
||||
|
||||
const getGraphURI = () => {
|
||||
let graphUri = defaultGraphUri;
|
||||
|
||||
try {
|
||||
const loc = location; // eslint-disable-line
|
||||
const search = (loc && loc.search) || '';
|
||||
const host = (loc && loc.host) || '';
|
||||
const query = queryString.parse(search);
|
||||
const isLocal = host.includes('localhost');
|
||||
|
||||
if (query.graph) {
|
||||
// if a query param is provided - always use that.
|
||||
graphUri = query.graph;
|
||||
} else if (isLocal) {
|
||||
// If a query param is not provided - check if we're running locally or on heroku,
|
||||
// and if so default to /graphql for mocking purposes
|
||||
graphUri = '/graph';
|
||||
}
|
||||
} catch (err) {
|
||||
// just suppress this madness
|
||||
}
|
||||
|
||||
return graphUri;
|
||||
};
|
||||
|
||||
export const createQuery = (tokenFn, query, variables) => { // eslint-disable-line
|
||||
const apollo = createApolloFetch({ uri: defaultGraphUri });
|
||||
const apollo = createApolloFetch({ uri: getGraphURI() });
|
||||
|
||||
apollo.use(includeCredentials(tokenFn));
|
||||
// apollo.useAfter(trackErrors);
|
||||
|
||||
Reference in New Issue
Block a user