[mocks][xs]: refactor mock server module.
This commit is contained in:
@@ -4,16 +4,7 @@ const { makeExecutableSchema } = require('graphql-tools');
|
|||||||
const { importSchema } = require('graphql-import');
|
const { importSchema } = require('graphql-import');
|
||||||
const typeDefs = importSchema('./schema.graphql');
|
const typeDefs = importSchema('./schema.graphql');
|
||||||
|
|
||||||
const resolvers = {
|
const gdp = {
|
||||||
Query: {
|
|
||||||
search: (parent, { query }) => ({
|
|
||||||
success: true,
|
|
||||||
result: {
|
|
||||||
count: 2,
|
|
||||||
sort: 'score desc, metadata_modified desc',
|
|
||||||
facets: {},
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
name: 'gdp',
|
name: 'gdp',
|
||||||
title: 'Country, Regional and World GDP (Gross Domestic Product)',
|
title: 'Country, Regional and World GDP (Gross Domestic Product)',
|
||||||
notes:
|
notes:
|
||||||
@@ -41,8 +32,9 @@ const resolvers = {
|
|||||||
},
|
},
|
||||||
metadata_created: '2019-03-07T11:56:19.696257',
|
metadata_created: '2019-03-07T11:56:19.696257',
|
||||||
metadata_modified: '2019-03-07T12:03:58.817280',
|
metadata_modified: '2019-03-07T12:03:58.817280',
|
||||||
},
|
};
|
||||||
{
|
|
||||||
|
const population = {
|
||||||
name: 'population',
|
name: 'population',
|
||||||
title: 'World population data',
|
title: 'World population data',
|
||||||
notes:
|
notes:
|
||||||
@@ -68,8 +60,19 @@ const resolvers = {
|
|||||||
image_url:
|
image_url:
|
||||||
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
],
|
|
||||||
|
const datapackages = [gdp, population];
|
||||||
|
|
||||||
|
const resolvers = {
|
||||||
|
Query: {
|
||||||
|
search: (parent, { query }) => ({
|
||||||
|
success: true,
|
||||||
|
result: {
|
||||||
|
count: 2,
|
||||||
|
sort: 'score desc, metadata_modified desc',
|
||||||
|
facets: {},
|
||||||
|
results: datapackages,
|
||||||
search_facets: {},
|
search_facets: {},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -83,17 +86,7 @@ const schema = makeExecutableSchema({
|
|||||||
|
|
||||||
const server = new ApolloServer({
|
const server = new ApolloServer({
|
||||||
schema,
|
schema,
|
||||||
mocks: {
|
mocks: true,
|
||||||
success: () => {
|
|
||||||
return new Date();
|
|
||||||
},
|
|
||||||
result: () => {
|
|
||||||
return {
|
|
||||||
firstName: 'Kouki',
|
|
||||||
lastName: 'Saito',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen().then(({ url }) => {
|
server.listen().then(({ url }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user