mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 02:34:28 +11:00
Added full support for Boolean and Float types
This commit is contained in:
@@ -7,6 +7,11 @@ const parseQueryTree = (tokens, typeGraph, options) => {
|
||||
throw `Expected a type in the type graph (found ${tokens[current - 1]})`;
|
||||
}
|
||||
|
||||
//check that there are the correct number of '{' and '}'
|
||||
if (tokens.reduce((running, tok) => tok == '{' ? running + 1 : tok == '}' ? running - 1 : running, 0) != 0) {
|
||||
throw `Unequal number of '{' and '}' found`;
|
||||
}
|
||||
|
||||
//read the block of lines
|
||||
const [block, pos] = readBlock(tokens, current, tokens[current - 1], typeGraph, options);
|
||||
|
||||
@@ -27,12 +32,7 @@ const readBlock = (tokens, current, superType, typeGraph, options) => {
|
||||
const result = {};
|
||||
|
||||
//scan each "line" in this block
|
||||
while(tokens[current++]) {
|
||||
//check for end of block
|
||||
if (tokens[current - 1] == '}') {
|
||||
break;
|
||||
}
|
||||
|
||||
while(tokens[current++] && tokens[current - 1] != '}') {
|
||||
//check for block-level keywords (modifiers need to form a chain from the leaf)
|
||||
let modifier = null;
|
||||
if (['match'].includes(tokens[current - 1])) {
|
||||
|
||||
@@ -6,8 +6,8 @@ const Op = {
|
||||
const books = {
|
||||
findAll: async args => {
|
||||
let arr = [
|
||||
{ id: 1, title: 'The Wind in the Willows', published: '1908-06-15' },
|
||||
{ id: 2, title: 'The Fart in the Fronds', published: '1908-06-15' }
|
||||
{ id: 1, title: 'The Wind in the Willows', published: '1908-06-15', score: 0.9 },
|
||||
{ id: 2, title: 'The Fart in the Fronds', published: null, score: 0.45 }
|
||||
];
|
||||
|
||||
const { attributes, where } = args;
|
||||
@@ -18,19 +18,9 @@ const books = {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (where.title && where.published) {
|
||||
return element.title == where.title.eq && element.published == where.published.eq;
|
||||
}
|
||||
|
||||
if (where.title) {
|
||||
return element.title == where.title.eq;
|
||||
}
|
||||
|
||||
if (where.published) {
|
||||
return element.published == where.published.eq;
|
||||
}
|
||||
|
||||
return false;
|
||||
return Object.keys(where).reduce((result, key) => {
|
||||
return result && (element[key] || 'null').toString() == where[key].eq.toString();
|
||||
}, true);
|
||||
});
|
||||
|
||||
//filter out non-used attributes
|
||||
@@ -52,9 +42,9 @@ const books = {
|
||||
const authors = {
|
||||
findAll: async args => {
|
||||
let arr = [
|
||||
{ id: 1, name: 'Kenneth Grahame', books: [1] },
|
||||
{ id: 2, name: 'Frank', books: [1, 2] },
|
||||
{ id: 3, name: 'Betty', books: [2] }
|
||||
{ id: 1, name: 'Kenneth Grahame', books: [1], alive: false },
|
||||
{ id: 2, name: 'Frank', books: [1, 2], alive: true },
|
||||
{ id: 3, name: 'Betty', books: [2], alive: true }
|
||||
];
|
||||
|
||||
const { attributes, where } = args;
|
||||
@@ -65,19 +55,9 @@ const authors = {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (where.name && where.books) {
|
||||
return element.name == where.name.eq; //books is always true because they are never queried
|
||||
}
|
||||
|
||||
if (where.name) {
|
||||
return element.name == where.name.eq;
|
||||
}
|
||||
|
||||
if (where.books) {
|
||||
return true; //books is always true because they are never queried
|
||||
}
|
||||
|
||||
return false;
|
||||
return Object.keys(where).reduce((result, key) => {
|
||||
return result && (element[key] || 'null').toString() == where[key].eq.toString();
|
||||
}, true);
|
||||
});
|
||||
|
||||
//filter out non-used attributes
|
||||
@@ -215,11 +195,13 @@ scalar Date
|
||||
type Book {
|
||||
String title
|
||||
Date published
|
||||
Float score
|
||||
}
|
||||
|
||||
type Author {
|
||||
String name
|
||||
Book books
|
||||
Boolean alive
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user