I tried, and I failed. Mad props to those who wrote graphQL

This commit is contained in:
2020-03-04 16:48:29 +11:00
parent 8ef1d0efbd
commit 66d8cd7630
4 changed files with 100 additions and 7 deletions

View File

@@ -7,6 +7,24 @@ 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
return database.books.map(b => {
const ret = {};
if (scalars.some(s => s.name == 'title')) {
ret.title = b.title;
}
if (scalars.some(s => s.name == 'author')) {
ret.author = b.author;
}
if (scalars.some(s => s.name == 'published')) {
ret.published = b.published;
}
return ret;
});
},
Author: scalars => {