From 333154fd7b5c62ce345e045d8ce19114485a3185 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 22 Sep 2020 07:46:54 +1000 Subject: [PATCH] Added debugging option, bumped version to 0.2.1 --- README.md | 3 ++- index.js | 32 +++++++++++++++++++++----------- package.json | 2 +- test-server/package.json | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8d1d527..c5a412c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Things That Need To Be Done -* Debugging options +* ~~Debugging options~~ +* N + 1 problem solved * Full documentation * Graphical tool * GitHub CI testing diff --git a/index.js b/index.js index 95cce90..8b1865e 100644 --- a/index.js +++ b/index.js @@ -2,24 +2,22 @@ const keywords = ['type', 'scalar', 'create', 'update', 'delete', 'set', 'match']; //the main function to be returned -const main = (schema, handler) => { +const main = (schema, handler, options = {}) => { let typeGraph; try { - typeGraph = buildTypeGraph(schema); + typeGraph = buildTypeGraph(schema, options); } catch(e) { - console.log('caught in typegraph', e); + console.log('Type Graph Error:', e); return null; } - console.log(typeGraph); - //the receiving function - this will be called multiple times return async reqBody => { try { //parse the query - const tokens = lexify(reqBody, true); + const tokens = lexify(reqBody, true, options); let pos = 0; //check for keywords @@ -53,7 +51,7 @@ const main = (schema, handler) => { }; //parse the schema into a type graph -const buildTypeGraph = schema => { +const buildTypeGraph = (schema, options) => { //the default graph let graph = { String: { scalar: true }, @@ -63,14 +61,14 @@ const buildTypeGraph = schema => { }; //parse the schema - const tokens = lexify(schema, false); + const tokens = lexify(schema, false, options); let pos = 0; while (tokens[pos++]) { //check for keywords switch(tokens[pos - 1]) { case 'type': - graph[tokens[pos++]] = parseCompoundType(tokens, pos); + graph[tokens[pos++]] = parseCompoundType(tokens, pos, options); //advance to the end of the compound type pos = eatBlock(tokens, pos); @@ -90,10 +88,14 @@ const buildTypeGraph = schema => { } } + if (options.debug) { + console.log('Type Graph:\n', graph); + } + return graph; }; -const parseCompoundType = (tokens, pos) => { +const parseCompoundType = (tokens, pos, options) => { //format check (not strictly necessary, but it looks nice) if (tokens[pos] !== '{') { 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; }; @@ -258,7 +264,7 @@ const eatBlock = (tokens, pos) => { return pos; }; -const lexify = (body, allowStrings) => { +const lexify = (body, allowStrings, options) => { let current = 0; tokens = []; @@ -302,6 +308,10 @@ const lexify = (body, allowStrings) => { } } + if (options.debug) { + console.log('Lexify:\n', tokens); + } + return tokens; }; diff --git a/package.json b/package.json index 67644c5..38375ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sineql", - "version": "0.2.0", + "version": "0.2.1", "description": "A simple to use graphQL clone", "main": "index.js", "scripts": { diff --git a/test-server/package.json b/test-server/package.json index a76f9e4..307e004 100644 --- a/test-server/package.json +++ b/test-server/package.json @@ -1,6 +1,6 @@ { "name": "test-server", - "version": "0.2.0", + "version": "0.2.1", "description": "", "main": "server.js", "scripts": {