[apollo][xl]: mocked graphql setup + search page working from apollo now.
This commit is contained in:
30
mock/.gitignore
vendored
Normal file
30
mock/.gitignore
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
151
mock/index.js
Normal file
151
mock/index.js
Normal file
@@ -0,0 +1,151 @@
|
||||
const { GraphQLScalarType } = require('graphql');
|
||||
const { ApolloServer } = require('apollo-server');
|
||||
const { makeExecutableSchema } = require('graphql-tools');
|
||||
const { importSchema } = require('graphql-import');
|
||||
const typeDefs = `
|
||||
type Query {
|
||||
search(query: SearchQuery!): Response!
|
||||
}
|
||||
|
||||
input SearchQuery {
|
||||
q: String!
|
||||
}
|
||||
|
||||
type Response {
|
||||
success: Boolean!
|
||||
result: Result!
|
||||
}
|
||||
|
||||
type Result {
|
||||
count: Int!
|
||||
sort: String!
|
||||
facets: String!
|
||||
search_facets: String!
|
||||
results: [Package!]!
|
||||
}
|
||||
|
||||
type Package {
|
||||
name: String!
|
||||
title: String!
|
||||
notes: String!
|
||||
resources: [Resource!]!
|
||||
organization: Organization!
|
||||
metadata_created: String!
|
||||
metadata_modified: String!
|
||||
}
|
||||
|
||||
type Resource {
|
||||
name: String!
|
||||
id: String!
|
||||
title: String!
|
||||
format: String!
|
||||
created: String!
|
||||
last_modified: String!
|
||||
datastore_active: Boolean!
|
||||
url: String!
|
||||
}
|
||||
|
||||
type Organization {
|
||||
name: String!
|
||||
title: String!
|
||||
description: String!
|
||||
created: String!
|
||||
image_url: String!
|
||||
}
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
search: (parent, { query }) => ({
|
||||
success: true,
|
||||
result: {
|
||||
count: 2,
|
||||
sort: 'score desc, metadata_modified desc',
|
||||
facets: {},
|
||||
results: [
|
||||
{
|
||||
name: 'gdp',
|
||||
title: 'Country, Regional and World GDP (Gross Domestic Product)',
|
||||
notes:
|
||||
'Country, regional and world GDP in current US Dollars ($). Regional means collections of countries e.g. Europe & Central Asia. Data is sourced from the World Bank and turned into a standard normalized CSV.',
|
||||
resources: [
|
||||
{
|
||||
name: 'gdp',
|
||||
id: 'gdp',
|
||||
title: 'GDP data',
|
||||
format: 'csv',
|
||||
created: '2019-03-07T12:00:36.273495',
|
||||
last_modified: '2020-05-07T12:00:36.273495',
|
||||
datastore_active: false,
|
||||
url: 'http://mock.filestore/gdp.csv',
|
||||
},
|
||||
],
|
||||
organization: {
|
||||
title: 'World Bank',
|
||||
name: 'world-bank',
|
||||
description:
|
||||
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
||||
created: '2019-03-07T11:51:13.758844',
|
||||
image_url:
|
||||
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
||||
},
|
||||
metadata_created: '2019-03-07T11:56:19.696257',
|
||||
metadata_modified: '2019-03-07T12:03:58.817280',
|
||||
},
|
||||
{
|
||||
name: 'population',
|
||||
title: 'World population data',
|
||||
notes:
|
||||
'Population figures for countries, regions (e.g. Asia) and the world. Data comes originally from World Bank and has been converted into standard CSV.',
|
||||
resources: [
|
||||
{
|
||||
name: 'population',
|
||||
id: 'population',
|
||||
title: 'Population data',
|
||||
format: 'csv',
|
||||
created: '2019-03-07T12:00:36.273495',
|
||||
last_modified: '2020-05-07T12:00:36.273495',
|
||||
datastore_active: true,
|
||||
url: 'http://mock.filestore/population.csv',
|
||||
},
|
||||
],
|
||||
organization: {
|
||||
title: 'World Bank',
|
||||
name: 'world-bank',
|
||||
description:
|
||||
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
||||
created: '2019-03-07T11:51:13.758844',
|
||||
image_url:
|
||||
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
||||
},
|
||||
},
|
||||
],
|
||||
search_facets: {},
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
const schema = makeExecutableSchema({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
});
|
||||
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
mocks: {
|
||||
success: () => {
|
||||
return new Date();
|
||||
},
|
||||
result: () => {
|
||||
return {
|
||||
firstName: 'Kouki',
|
||||
lastName: 'Saito',
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
server.listen().then(({ url }) => {
|
||||
console.log(`🚀 Server ready at ${url}`);
|
||||
});
|
||||
3089
mock/package-lock.json
generated
Normal file
3089
mock/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
mock/package.json
Normal file
20
mock/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "mock",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"apollo-server": "^2.15.0",
|
||||
"graphql": "^15.1.0",
|
||||
"graphql-import": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user