Add graph-handling for different environments

This commit is contained in:
2019-01-15 14:27:15 +01:00
parent 5852ab4b56
commit 1ad951ca60
3 changed files with 42 additions and 2 deletions
+1
View File
@@ -15,6 +15,7 @@
"lodash": "^4.17.10",
"node-sass": "^4.9.0",
"nuxt": "^2.0.0",
"query-string": "^6.2.0",
"s-ago": "^1.3.0",
"sass-loader": "^7.0.3",
"vue": "^2.5.22",
+28 -2
View File
@@ -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);
+13
View File
@@ -6708,6 +6708,14 @@ qs@^6.4.0, qs@^6.5.1:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.6.0.tgz#a99c0f69a8d26bf7ef012f871cdabb0aee4424c2"
integrity sha512-KIJqT9jQJDQx5h5uAVPimw6yVg2SekOKu959OCtktD3FjzbpvaPr8i4zzg07DOMz+igA4W/aNM7OV8H37pFYfA==
query-string@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.2.0.tgz#468edeb542b7e0538f9f9b1aeb26f034f19c86e1"
integrity sha512-5wupExkIt8RYL4h/FE+WTg3JHk62e6fFPWtAZA9J5IWK1PfTfKkMS93HBUHcFpeYi9KsY5pFbh+ldvEyaz5MyA==
dependencies:
decode-uri-component "^0.2.0"
strict-uri-encode "^2.0.0"
querystring-es3@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
@@ -7592,6 +7600,11 @@ stream-to-observable@^0.1.0:
resolved "https://registry.yarnpkg.com/stream-to-observable/-/stream-to-observable-0.1.0.tgz#45bf1d9f2d7dc09bed81f1c307c430e68b84cffe"
integrity sha1-Rb8dny19wJvtgfHDB8Qw5ouEz/4=
strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
string-width@^1.0.1, string-width@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"