Initial commit

This commit is contained in:
2019-01-15 13:21:24 +01:00
commit dc50642ed9
49 changed files with 10493 additions and 0 deletions
@@ -0,0 +1,15 @@
import {
findEvents,
} from '../index';
const verifyResponse = (response) => {
expect(response.errors).toBe(undefined);
};
const verifyError = (response) => {
expect(response.errors.length).toBeGreaterThan(0);
};
describe('GQL Queries', () => {
test('findEvents', () => findEvents().then(verifyResponse));
});
+11
View File
@@ -0,0 +1,11 @@
export {
findEvents
} from './queries';
export {
ignoreBand,
ignoreDanceHall,
ignoreCity,
ignoreMunicipality,
ignoreState
} from './mutations';
+15
View File
@@ -0,0 +1,15 @@
module.exports = {
includeCredentials: (tokenFn) => {
return ({options}, next) => {
if (!options.headers) {
options.headers = {}; // Create the headers object if needed.
}
const token = tokenFn();
if (token) {
options.headers['Authorization'] = 'Bearer ' + tokenFn();
}
options.credentials = 'same-origin'; // eslint-disable-line
next();
}
},
};
+27
View File
@@ -0,0 +1,27 @@
module.exports = {
ignoreBandMutation: `
mutation IgnoreBand($name: String!) {
ignore: IgnoreBand(name: $name)
}
`,
ignoreDanceHallMutation: `
mutation IgnoreDanceHall($name: String!) {
ignore: IgnoreDanceHall(name: $name)
}
`,
ignoreCityMutation: `
mutation IgnoreCity($name: String!) {
ignore: IgnoreCity(name: $name)
}
`,
ignoreMunicipalityMutation: `
mutation IgnoreMunicipality($name: String!) {
ignore: IgnoreMunicipality(name: $name)
}
`,
ignoreStateMutation: `
mutation IgnoreState($name: String!) {
ignore: IgnoreState(name: $name)
}
`
};
+27
View File
@@ -0,0 +1,27 @@
import { createQuery } from './utils';
import {
ignoreBandMutation,
ignoreDanceHallMutation,
ignoreCityMutation,
ignoreMunicipalityMutation,
ignoreStateMutation,
} from './mutationStrings';
import webAuth from '../auth';
/* eslint-disable max-len */
export const ignoreBand = variables => {
return createQuery(webAuth.idToken, ignoreBandMutation, variables)
};
export const ignoreDanceHall = variables => {
return createQuery(webAuth.idToken, ignoreDanceHallMutation, variables)
};
export const ignoreCity = variables => {
return createQuery(webAuth.idToken, ignoreCityMutation, variables)
};
export const ignoreMunicipality = variables => {
return createQuery(webAuth.idToken, ignoreMunicipalityMutation, variables)
};
export const ignoreState = variables => {
return createQuery(webAuth.idToken, ignoreStateMutation, variables)
};
/* eslint-enable max-len */
+10
View File
@@ -0,0 +1,10 @@
import { createQuery } from './utils';
import {
eventQuery,
} from './queryStrings';
import webAuth from '../auth';
/* eslint-disable max-len */
export const findEvents = () => createQuery(webAuth.idToken, eventQuery);
/* eslint-enable max-len */
+18
View File
@@ -0,0 +1,18 @@
export const eventQuery = `
{
events: Events {
date
time
band {
name
}
danceHall {
name
city
municipality
state
}
extraInfo
}
}
`;
+13
View File
@@ -0,0 +1,13 @@
const { createApolloFetch } = require('apollo-fetch');
const { includeCredentials } = require('./middleware');
const defaultGraphUri = '/graph';
export const createQuery = (tokenFn, query, variables) => { // eslint-disable-line
const apollo = createApolloFetch({ uri: defaultGraphUri });
apollo.use(includeCredentials(tokenFn));
// apollo.useAfter(trackErrors);
return apollo({ query, variables });
};