mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 02:34:28 +11:00
Added debugging option, bumped version to 0.2.1
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# Things That Need To Be Done
|
# Things That Need To Be Done
|
||||||
|
|
||||||
* Debugging options
|
* ~~Debugging options~~
|
||||||
|
* N + 1 problem solved
|
||||||
* Full documentation
|
* Full documentation
|
||||||
* Graphical tool
|
* Graphical tool
|
||||||
* GitHub CI testing
|
* GitHub CI testing
|
||||||
|
|||||||
32
index.js
32
index.js
@@ -2,24 +2,22 @@
|
|||||||
const keywords = ['type', 'scalar', 'create', 'update', 'delete', 'set', 'match'];
|
const keywords = ['type', 'scalar', 'create', 'update', 'delete', 'set', 'match'];
|
||||||
|
|
||||||
//the main function to be returned
|
//the main function to be returned
|
||||||
const main = (schema, handler) => {
|
const main = (schema, handler, options = {}) => {
|
||||||
let typeGraph;
|
let typeGraph;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
typeGraph = buildTypeGraph(schema);
|
typeGraph = buildTypeGraph(schema, options);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log('caught in typegraph', e);
|
console.log('Type Graph Error:', e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(typeGraph);
|
|
||||||
|
|
||||||
//the receiving function - this will be called multiple times
|
//the receiving function - this will be called multiple times
|
||||||
return async reqBody => {
|
return async reqBody => {
|
||||||
try {
|
try {
|
||||||
//parse the query
|
//parse the query
|
||||||
const tokens = lexify(reqBody, true);
|
const tokens = lexify(reqBody, true, options);
|
||||||
let pos = 0;
|
let pos = 0;
|
||||||
|
|
||||||
//check for keywords
|
//check for keywords
|
||||||
@@ -53,7 +51,7 @@ const main = (schema, handler) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//parse the schema into a type graph
|
//parse the schema into a type graph
|
||||||
const buildTypeGraph = schema => {
|
const buildTypeGraph = (schema, options) => {
|
||||||
//the default graph
|
//the default graph
|
||||||
let graph = {
|
let graph = {
|
||||||
String: { scalar: true },
|
String: { scalar: true },
|
||||||
@@ -63,14 +61,14 @@ const buildTypeGraph = schema => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//parse the schema
|
//parse the schema
|
||||||
const tokens = lexify(schema, false);
|
const tokens = lexify(schema, false, options);
|
||||||
let pos = 0;
|
let pos = 0;
|
||||||
|
|
||||||
while (tokens[pos++]) {
|
while (tokens[pos++]) {
|
||||||
//check for keywords
|
//check for keywords
|
||||||
switch(tokens[pos - 1]) {
|
switch(tokens[pos - 1]) {
|
||||||
case 'type':
|
case 'type':
|
||||||
graph[tokens[pos++]] = parseCompoundType(tokens, pos);
|
graph[tokens[pos++]] = parseCompoundType(tokens, pos, options);
|
||||||
|
|
||||||
//advance to the end of the compound type
|
//advance to the end of the compound type
|
||||||
pos = eatBlock(tokens, pos);
|
pos = eatBlock(tokens, pos);
|
||||||
@@ -90,10 +88,14 @@ const buildTypeGraph = schema => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log('Type Graph:\n', graph);
|
||||||
|
}
|
||||||
|
|
||||||
return graph;
|
return graph;
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseCompoundType = (tokens, pos) => {
|
const parseCompoundType = (tokens, pos, options) => {
|
||||||
//format check (not strictly necessary, but it looks nice)
|
//format check (not strictly necessary, but it looks nice)
|
||||||
if (tokens[pos] !== '{') {
|
if (tokens[pos] !== '{') {
|
||||||
throw 'Expected \'{\' in compound type definition';
|
throw 'Expected \'{\' in compound type definition';
|
||||||
@@ -127,6 +129,10 @@ const parseCompoundType = (tokens, pos) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log('Compound Type:\n', compound);
|
||||||
|
}
|
||||||
|
|
||||||
return compound;
|
return compound;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -258,7 +264,7 @@ const eatBlock = (tokens, pos) => {
|
|||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
const lexify = (body, allowStrings) => {
|
const lexify = (body, allowStrings, options) => {
|
||||||
let current = 0;
|
let current = 0;
|
||||||
tokens = [];
|
tokens = [];
|
||||||
|
|
||||||
@@ -302,6 +308,10 @@ const lexify = (body, allowStrings) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log('Lexify:\n', tokens);
|
||||||
|
}
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sineql",
|
"name": "sineql",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"description": "A simple to use graphQL clone",
|
"description": "A simple to use graphQL clone",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "test-server",
|
"name": "test-server",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user