-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
James Chang edited this page Mar 27, 2021
·
1 revision
GiraffeQL is available as an NPM package. It is built on top of the express.js framework. To install GiraffeQL in your express project, you will need to run npm install --save giraffeql
.
From an empty project directory, do the following:
npm init -y
npm install --save express giraffeql
// index.js
const express = require("express");
const { initializeGiraffeql } = require("giraffeql");
require("./schema");
const app = express();
app.use(express.json());
const port = 8080;
initializeGiraffeql(app, {
debug: true,
lookupValue: true,
});
// start the Express server
app.listen(port, () => {
console.log(`server started at http://localhost:${port}`);
});
// schema.js
// register the root resolver
const { GiraffeqlRootResolverType, BaseScalars } = require("giraffeql");
module.exports = new GiraffeqlRootResolverType({
name: "getHelloWorld",
restOptions: {
method: "get",
route: "/hello_world",
},
allowNull: false,
type: BaseScalars.string,
resolver: () => "Hello World",
});
node .
POST http://localhost:8080/giraffeql
{
"getHelloWorld": true
}
GET http://localhost:8080/hello_world
Code available at this repository: https://github.com/big213/giraffeql-hello-world