Layed out a fake database

This commit is contained in:
2020-03-04 09:25:35 +11:00
parent 4d06e3e84c
commit 8ef1d0efbd
5 changed files with 83 additions and 11 deletions

42
server/database.js Normal file
View File

@@ -0,0 +1,42 @@
//the authors
let authors = [
{
name: 'J.K. Roaring',
books: [
{ title: 'The Philosepher\'s Kidney Stone' },
{ title: 'The Chamber Pot of Secrets' },
{ title: 'The Prisoner of Aunt Kazban' },
{ title: 'The Goblet of the Fire Cocktail' },
{ title: 'The Order for Kleenex' },
{ title: 'The Half-Priced Pharmacy' },
{ title: 'Yeah, I Got Nothing' },
]
},
{
name: 'Kenneth Grahame',
books: [
{ title: 'The Wind in the Willows', published: '1 April 1908' }
]
},
];
//insert the authors into the books
authors = authors.map(a => {
a.books = a.books.map(b => {
b.author = a;
return b;
});
return a;
});
//get the book array
let books = [];
authors.forEach(a => books = books.concat(a.books));
//the fake database
module.exports = {
authors,
books,
};

30
server/handler.js Normal file
View File

@@ -0,0 +1,30 @@
const database = require('./database.js');
console.log(database);
//the handler routines
const handler = {
Book: scalars => {
//takes an array of scalar types as objects: { typeName: 'String', name: 'title' }
//must return an array of objects containing the results
},
Author: scalars => {
//takes an array of scalar types as objects: { typeName: 'String', name: 'name' }
//must return an array of objects containing the results
},
create: (sets, matches) => {
//TODO
},
update: (sets, matches) => {
//TODO
},
delete: matches => {
//TODO
},
};
module.exports = handler;

View File

@@ -1,21 +1,21 @@
//express for testing
const express = require('express');
const path = require('path');
const app = express();
//test the library
const schema = require('./schema.js');
//const handler = requre('./handler.js');
const handler = require('./handler.js');
const simpleQL = require('./simpleQL');
const simple = simpleQL(schema);
const simple = simpleQL(schema, handler);
//open the end
app.post('simpleQL', (req, res) => {
res.status(200).send(simple(req.body));
app.post('/simpleql', (req, res) => {
const [code, result] = simple(req.body);
res.status(code).send(result);
});
//startup
app.listen(process.env.WEB_PORT || 3100, (err) => {
console.log(`listening to *:${process.env.WEB_PORT || 3100}`);
});
app.listen(process.env.WEB_PORT || 3100, err => {
console.log(`listening to *:${process.env.WEB_PORT || 3100}`);
});

View File

@@ -6,7 +6,7 @@ const main = (schema, handler) => {
//the receiving function - this will be called multiple times
return reqBody => {
return '';
return [200, ''];
};
};