mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 10:44:28 +11:00
Layed out a fake database
This commit is contained in:
@@ -114,7 +114,7 @@ create Book [
|
|||||||
set title "The Prisoner of Aunt Kazban"
|
set title "The Prisoner of Aunt Kazban"
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
set title "The Goblet of Fire Cocktail"
|
set title "The Goblet of the Fire Cocktail"
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
set title "The Order for Kleenex"
|
set title "The Order for Kleenex"
|
||||||
@@ -123,7 +123,7 @@ create Book [
|
|||||||
set title "The Half-Priced Pharmacy"
|
set title "The Half-Priced Pharmacy"
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
set title "Yeah, I got nothing"
|
set title "Yeah, I Got Nothing"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
42
server/database.js
Normal file
42
server/database.js
Normal 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
30
server/handler.js
Normal 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;
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
//express for testing
|
//express for testing
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
//test the library
|
//test the library
|
||||||
const schema = require('./schema.js');
|
const schema = require('./schema.js');
|
||||||
//const handler = requre('./handler.js');
|
const handler = require('./handler.js');
|
||||||
const simpleQL = require('./simpleQL');
|
const simpleQL = require('./simpleQL');
|
||||||
|
|
||||||
const simple = simpleQL(schema);
|
const simple = simpleQL(schema, handler);
|
||||||
|
|
||||||
//open the end
|
//open the end
|
||||||
app.post('simpleQL', (req, res) => {
|
app.post('/simpleql', (req, res) => {
|
||||||
res.status(200).send(simple(req.body));
|
const [code, result] = simple(req.body);
|
||||||
|
res.status(code).send(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
//startup
|
//startup
|
||||||
app.listen(process.env.WEB_PORT || 3100, (err) => {
|
app.listen(process.env.WEB_PORT || 3100, err => {
|
||||||
console.log(`listening to *:${process.env.WEB_PORT || 3100}`);
|
console.log(`listening to *:${process.env.WEB_PORT || 3100}`);
|
||||||
});
|
});
|
||||||
@@ -6,7 +6,7 @@ const main = (schema, handler) => {
|
|||||||
|
|
||||||
//the receiving function - this will be called multiple times
|
//the receiving function - this will be called multiple times
|
||||||
return reqBody => {
|
return reqBody => {
|
||||||
return '';
|
return [200, ''];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user