[mocks][m]: setup CKAN api mocks with the new apollo setup.

This commit is contained in:
anuveyatsu 2020-06-23 10:43:53 +06:00
parent 50119bf33f
commit 55d9c68b34
4 changed files with 39 additions and 20 deletions

View File

@ -7,7 +7,7 @@ import { RestLink } from 'apollo-link-rest';
let apolloClient;
const restLink = new RestLink({
uri: 'https://demo.ckan.org/api/3/action/',
uri: getConfig().publicRuntimeConfig.DMS + '/api/3/action/',
typePatcher: {
Search: (
data: any,

View File

@ -66,9 +66,7 @@ module.exports.initMocks = function () {
nock('http://mock.ckan/api/3/action', { encodedQueryParams: true })
.persist()
// 1. Call without query.
.get(
'/package_search?facet.field=organization&facet.field=groups&facet.field=tags&facet.field=res_format&facet.field=license_id&facet.limit=5'
)
.get('/package_search?')
.reply(200, {
success: true,
result: {
@ -80,9 +78,7 @@ module.exports.initMocks = function () {
},
})
// 2. Call with `q=gdp` query.
.get(
'/package_search?q=gdp&facet.field=organization&facet.field=groups&facet.field=tags&facet.field=res_format&facet.field=license_id&facet.limit=5'
)
.get('/package_search?q=gdp')
.reply(200, {
success: true,
result: {

View File

@ -1,7 +1,37 @@
module.exports = {
publicRuntimeConfig: {
graphqlEndpoint:
process.env.GRAPHQL_ENDPOINT ||
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
},
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
module.exports = (phase, { defaultConfig }) => {
const dms = process.env.DMS;
if (phase === PHASE_DEVELOPMENT_SERVER) {
if (dms) {
console.log('\nYou are running the app in dev mode 🌀');
console.log(
'Did you know that you can use mocked CKAN API? Just unset your `DMS` env var.'
);
console.log('Happy coding ☀️\n');
} else {
const mocks = require('./mocks');
mocks.initMocks();
console.log(
'\nYou have not defined any DMS API so we are activating the mocks ⚠️'
);
console.log(
'If you wish to run against your CKAN API, you can set `DMS` env var.'
);
console.log(
'For example, to run against demo ckan site: `DMS=https://demo.ckan.org`\n'
);
}
return {
publicRuntimeConfig: {
DMS: dms ? dms.replace(/\/?$/, '') : 'http://mock.ckan',
},
};
}
return {
publicRuntimeConfig: {
DMS: dms ? dms.replace(/\/?$/, '') : 'https://demo.ckan.org',
},
};
};

View File

@ -4,13 +4,6 @@ import '../styles/index.css';
import { ApolloProvider } from '@apollo/react-hooks';
import { useApollo } from '../lib/apolloClient';
// Setup mocks
// if (process.env.NODE_ENV === 'development') {
// const mocks = require('../mocks');
// mocks.initMocks();
// console.warn('You have activated the mocks.');
// }
export default function MyApp({ Component, pageProps }) {
const apolloClient = useApollo(pageProps.initialApolloState);