Initial commit
This commit is contained in:
@@ -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));
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
export {
|
||||
findEvents
|
||||
} from './queries';
|
||||
|
||||
export {
|
||||
ignoreBand,
|
||||
ignoreDanceHall,
|
||||
ignoreCity,
|
||||
ignoreMunicipality,
|
||||
ignoreState
|
||||
} from './mutations';
|
||||
@@ -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();
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -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)
|
||||
}
|
||||
`
|
||||
};
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -0,0 +1,18 @@
|
||||
export const eventQuery = `
|
||||
{
|
||||
events: Events {
|
||||
date
|
||||
time
|
||||
band {
|
||||
name
|
||||
}
|
||||
danceHall {
|
||||
name
|
||||
city
|
||||
municipality
|
||||
state
|
||||
}
|
||||
extraInfo
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -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 });
|
||||
};
|
||||
Reference in New Issue
Block a user