mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 02:34:28 +11:00
Added unique keyword
This commit is contained in:
@@ -103,12 +103,13 @@ wave('Author { name books { title } }')
|
||||
|
||||
## The Schema Language
|
||||
|
||||
The schema language is a layout of how queries should be made, as well as what can be made with them. There are two built-in keywords for the schema language:
|
||||
The schema language is a layout of how queries should be made, as well as what can be made with them. There are several built-in keywords for the schema language:
|
||||
|
||||
* type
|
||||
* scalar
|
||||
* unique
|
||||
|
||||
`type` is used for defining new compound types. `scalar` is for defining new scalar types, such as `Date`.
|
||||
`type` is used for defining new compound types. `scalar` is for defining new scalar types, such as `Date`. `unique` is a modifier on a field, indicating that it is unique in the database.
|
||||
|
||||
The built-in types for the schema language are:
|
||||
|
||||
@@ -123,12 +124,12 @@ These can be combined into compound types as so:
|
||||
scalar Date
|
||||
|
||||
type Book {
|
||||
String title
|
||||
unique String title
|
||||
Date published
|
||||
}
|
||||
|
||||
type Author {
|
||||
String name
|
||||
unique String name
|
||||
Book books
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sineql",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"description": "A simple to use graphQL clone",
|
||||
"main": "source/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -38,7 +38,8 @@ const buildTypeGraph = (schema, options) => {
|
||||
graph[tokens[pos++]] = { typeName: tokens[pos - 1], scalar: true };
|
||||
|
||||
if (options.debug) {
|
||||
console.log(`Defined ${tokens[pos - 1]}:\n`, graph[tokens[pos - 1]]);
|
||||
console.log(`Defined ${tokens[pos - 1]}:`);
|
||||
console.log(graph[tokens[pos - 1]], '\n');
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -49,7 +50,8 @@ const buildTypeGraph = (schema, options) => {
|
||||
}
|
||||
|
||||
if (options.debug) {
|
||||
console.log('\nType Graph:\n', graph, '\n');
|
||||
console.log('\nType Graph:');
|
||||
console.log(graph, '\n');
|
||||
}
|
||||
|
||||
return graph;
|
||||
@@ -62,11 +64,24 @@ const parseCompoundType = (tokens, pos, scalars, options) => {
|
||||
throw 'Expected \'{\' in compound type definition';
|
||||
}
|
||||
|
||||
//schema modifiers
|
||||
let modifiers = {};
|
||||
|
||||
//graph component to be returned
|
||||
const compound = { typeName: tokens[pos - 1] };
|
||||
|
||||
//for each line of the compound type
|
||||
while (tokens[pos++] && tokens[pos] !== '}') {
|
||||
//check for modifiers
|
||||
while(['unique'].includes(tokens[pos])) {
|
||||
if (Object.keys(modifiers).includes(tokens[pos])) {
|
||||
throw `Unexpected duplicate modifier in schema (${tokens[pos]})`;
|
||||
}
|
||||
|
||||
modifiers[tokens[pos++]] = true;
|
||||
}
|
||||
|
||||
//scan the type & name
|
||||
let type = tokens[pos++];
|
||||
const name = tokens[pos];
|
||||
|
||||
@@ -91,12 +106,16 @@ const parseCompoundType = (tokens, pos, scalars, options) => {
|
||||
|
||||
//finally, push to the compound definition
|
||||
compound[name] = {
|
||||
typeName: type
|
||||
typeName: type,
|
||||
...modifiers
|
||||
};
|
||||
|
||||
modifiers = {}; //reset
|
||||
}
|
||||
|
||||
if (options.debug) {
|
||||
console.log(`Defined ${options.debugName}:\n`, compound);
|
||||
console.log(`Defined ${options.debugName}:`);
|
||||
console.log(compound, '\n');
|
||||
}
|
||||
|
||||
return compound;
|
||||
|
||||
@@ -1 +1 @@
|
||||
["type", "scalar", "create", "update", "delete", "set", "match", "typeName"]
|
||||
["type", "scalar", "create", "update", "delete", "set", "match", "unique", "typeName"]
|
||||
@@ -11,6 +11,7 @@ module.exports = sequelize.define('authors', {
|
||||
},
|
||||
|
||||
name: {
|
||||
type: Sequelize.TEXT
|
||||
type: Sequelize.STRING,
|
||||
unique: true
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,11 +11,12 @@ module.exports = sequelize.define('books', {
|
||||
},
|
||||
|
||||
title: {
|
||||
type: Sequelize.TEXT
|
||||
type: Sequelize.STRING,
|
||||
unique: true
|
||||
},
|
||||
|
||||
published: {
|
||||
type: Sequelize.TEXT
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
|
||||
rating: {
|
||||
|
||||
@@ -3,13 +3,13 @@ module.exports = `
|
||||
scalar Date
|
||||
|
||||
type Book {
|
||||
String title
|
||||
unique String title
|
||||
Date published
|
||||
Float rating
|
||||
}
|
||||
|
||||
type Author {
|
||||
String name
|
||||
unique String name
|
||||
Book books
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user