diff --git a/README.md b/README.md index 04b1aae..c0f3595 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ sineQL is a web API query language that mimics graphQL, designed solely for fun. -sineQL consists of two languages - the schema language, and the query language. sineQL assumes that the records are related in a non-looping tree-structure, defined by the schema language. +sineQL consists of two languages - the schema language, and the query language. sineQL assumes that the records are related in a non-looping tree-structure, defined by the schema language. Also, each non-scalar type queried is returned as an array. + +The handler's definition is left up to the user. ## Example Server diff --git a/package.json b/package.json index 60c825a..7cc55cc 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,9 @@ { "name": "sineql", - "version": "0.2.1", + "version": "0.3.0", "description": "A simple to use graphQL clone", "main": "source/index.js", "scripts": { - "test": "cd test-server-books && npm install && npm run node", - "pokemon": "cd test-server-pokemon && npm install && npm run node" }, "repository": { "type": "git", diff --git a/source/build-type-graph.js b/source/build-type-graph.js index 11e43fa..6a516cf 100644 --- a/source/build-type-graph.js +++ b/source/build-type-graph.js @@ -22,7 +22,7 @@ const buildTypeGraph = (schema, options) => { switch(tokens[pos - 1]) { case 'type': //delegate - graph[tokens[pos++]] = parseCompoundType(tokens, pos, Object.keys(graph), options); + graph[tokens[pos++]] = parseCompoundType(tokens, pos, Object.keys(graph), { ...options, debugName: tokens[pos - 1] }); //advance to the end of the compound type pos = eatBlock(tokens, pos); @@ -31,12 +31,16 @@ const buildTypeGraph = (schema, options) => { case 'scalar': //check against keyword list - if (keywords.includes(graph[tokens[pos - 1]])) { - //TODO: test this error - throw 'Unexpected keyword ' + graph[tokens[pos - 1]]; + if (keywords.includes(tokens[pos])) { + throw 'Unexpected keyword ' + tokens[pos]; } graph[tokens[pos++]] = { scalar: true }; + + if (options.debug) { + console.log(`Defined ${tokens[pos - 1]}:\n`, graph[tokens[pos - 1]]); + } + break; default: @@ -45,7 +49,7 @@ const buildTypeGraph = (schema, options) => { } if (options.debug) { - console.log('Type Graph:\n', graph, '\n'); + console.log('\nType Graph:\n', graph, '\n'); } return graph; @@ -76,7 +80,7 @@ const parseCompoundType = (tokens, pos, scalars, options) => { } //can only use existing types (prevents looping tree structure) - if (!scalars.includes(type)) { //TODO: test this error + if (!scalars.includes(type)) { throw `Unexpected value found as type field ('${type}' is undefined)`; } @@ -92,7 +96,7 @@ const parseCompoundType = (tokens, pos, scalars, options) => { } if (options.debug) { - console.log('Compound Type:\n', compound, '\n'); + console.log(`Defined ${options.debugName}:\n`, compound); } return compound; diff --git a/source/index.js b/source/index.js index 72e5f93..a5c17de 100644 --- a/source/index.js +++ b/source/index.js @@ -1,6 +1,5 @@ const buildTypeGraph = require('./build-type-graph'); const parseInput = require('./parse-input'); -const parseQuery = require('./parse-query'); //the main function to be returned (sineQL()) const sineQL = (schema, handler, options = {}) => { diff --git a/source/parse-input.js b/source/parse-input.js index 418545e..e7106a0 100644 --- a/source/parse-input.js +++ b/source/parse-input.js @@ -44,7 +44,7 @@ const parseInput = (body, allowStrings, options) => { } if (options.debug) { - console.log('Input:\n', tokens, '\n'); + console.log('Input:', tokens, '\n'); } return tokens; diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..795dc04 --- /dev/null +++ b/test/index.js @@ -0,0 +1,23 @@ +//the library to test +const sineQL = require('../source/index.js'); + +//the dummy values +const schema = ` +scalar Date + +type Book { + String title + Date published +} + +type Author { + String name + Book books +} +`; + +const handler = null; + +//run the function in debug mode (builds type graph) +const sine = sineQL(schema, handler, { debug: true }); + diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..d8bd1a8 --- /dev/null +++ b/test/package.json @@ -0,0 +1,11 @@ +{ + "name": "sineql-test", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Kayne Ruse", + "license": "ISC" +}