A tiny JSON-based query language inspired by GraphQL
A tiny JSON-based query language inspired by GraphQL
Pronounced "miniquel", similar to "miniscule".
New to this? Check out the examples below or jump to getting started.
For a quick idea of what queries look like and how they work, jump straight into the interactive example.
Love this? Please star this repo!
There's an interactive browser-only example of MiniQL here:
https://miniql.github.io/miniql-interactive-example/
You fnd find the code for it here:
https://github.com/miniql/miniql-interactive-example
Here is an example of making MiniQL queries against a CSV file dataset under Node.js:
https://github.com/miniql/miniql-csv-example
Here is an example of making MiniQL queries against a JSON file dataset under Node.js:
https://github.com/miniql/miniql-json-example
Here is an easy to read MiniQL example in a JavaScript notebook
https://miniql.github.io/notebook-example/
Here is an example of using MiniQL to make queries against a MongoDB database through an Express REST API to display query results in the frontend.
https://github.com/miniql/miniql-express-mongodb-example
GraphQL is awesome, but sometimes the following can be annoying...
MiniQL delegates queries for entities to the query resolver.
The query resolver is something that you implmenent or is provided by a MiniQL plugin (such as the JSON plugin, the CSV plugin or the Inline data plugin).
Implementing your own resolver means you can have what ever features you like in the backend.
Adding features like these is completely under your control:
You can manage how data is returned, e.g:
Install MiniQL:
npm install --save miniql
Import MiniQL (JavaScript):
const { miniql } = require("miniql");
Import MiniQL (TypeScript):
import { miniql } from "miniql";
Now we must create a query resolver. For this example we'll use a character
entity (see the Star Wars data in the interactive example).
We need to define functions for retrieving and updating our character entity:
const queryResolver = {
get: {
character: {
invoke: async (args: any, context: any) => { // Handles a 'get' query.
if (args.name !== undefined) {
// Asking for a particular named character.
// Look up the single named character in your database and return it.
const theCharacter = ...;
return theCharacter;
}
else {
// Asking for all characters.
// Look up all characters in your database and return them.
const allCharacters = ...;
return allCharacters;
}
}
}
},
update: {
character: {
invoke: async (args: any, context: any) => { // Handles an 'update' query.
if (args.name !== undefined) {
const updateParams = args.params;
// Store `updateParams` against the single
// named character in your database.
}
else {
const updateParams = args.params;
// Add a new named character with
// `updateParams` in your database.
}
},
},
},
};
There's various plugins that can create a query resolver for us depending on our data source:
A MonogDB query resolver is coming soon! If you'd like to implement a resolver for your own favorite database please let me know.
Now that we have a query resolver we can execute queries against it with MiniQL.
First we need a query, let's create one to get the character called "Darth Vader":
const getQuery = {
get: { // This is a 'get' operation.
character: {
args: {
name: "Darth Vader", // We are retrieving the record for Mr Vader.
},
},
},
};
Now we can execute the get
query to retreive the record for Mr Vader:
const context = {}; // Global context passed to our resolver.
const queryResult = await miniql(getQuery, queryResolver, {}); // Executes the query.
console.log(queryResult);
Here's the output of the query:
{
"character": {
"name": "Darth Vader",
"height": 202,
"mass": 136,
"hair_color": "none",
"skin_color": "white",
"eye_color": "yellow",
"birth_year": "41.9BBY",
"gender": "male",
"homeworld": "Tatooine",
"species": "Human"
}
}
Now let's execute an update
query to modify mr Vader's record:
const updateQuery = {
update: { // This is an 'update' operation.
character: {
args: {
name: "Darth Vader",
params: {
// Sets Mr Vaders hair color.
hair_color: "brown", // At least it was brown back when he had hair.
},
},
},
},
};
Now we execute the update
query against our query resolver:
const context = {};
await miniql(updateQuery, queryResolver, {});
Mr Vader's hair color is now set to "brown".
Have fun with MiniQL!
More advanced documentation is coming soon! Follow for updates.