Skip to content

Getting Started

James Chang edited this page Feb 1, 2021 · 7 revisions

JomQL is available as an NPM package. It is built on top of the express.js framework. To install jomQL in your express project, you will need to run npm install --save jomql.

Hello World Basic Example

From an empty project directory, do the following:

npm init -y
npm install --save express jomql
// index.js
const express = require("express");

const { initializeJomql } = require("jomql");
require("./schema");

const app = express();
app.use(express.json());
const port = 8080;

initializeJomql(app, {
  debug: true,
  lookupValue: true,
  jomqlPath: "/jomql",
});

// start the Express server
app.listen(port, () => {
  console.log(`server started at http://localhost:${port}`);
});
// schema.js
// register the root resolver

const { JomqlRootResolverType, BaseScalars } = require("jomql");

module.exports = new JomqlRootResolverType({
  name: "getHelloWorld",
  restOptions: {
    method: "get",
    route: "/hello_world",
  },
  allowNull: false,
  type: BaseScalars.string,
  resolver: () => "Hello World",
});

Running the code

node .

Example Requests

POST http://localhost:8080/jomql
{
  "getHelloWorld": true
}
GET http://localhost:8080/hello_world

Code available at this repository: https://github.com/big213/jomql-hello-world

Clone this wiki locally