almilo / granate

Granate container for annotated GraphQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

granate

npm version Build Status Coverage Status

Build better APIs with annotated GraphQL

Introduction

GraphQL is an amazing technology that allows to build application APIs in a much better way than by implementing REST services. A GraphQL schema can be defined using a textual representation (schema language) which, when extended by mean of annotations (decorators with GraphQL directive syntax), leverages a lot of really useful possibilities. Granate helps you to build executable schemas with no code and evolve them rapidly.

Usage from the CLI

In order to use granate from the CLI, install granate-cli with the following command:

> npm i -g granate-cli
# file: todos.graphqls

type Todo {
    id: ID
    title: String
    completed: Boolean
}

type Query {
    todos: [Todo]
}
> granate serve todos.graphqls -a

Annotations: 'mock,rest' enabled.
Granate server listening on: 'http://localhost:4000/graphql'.

Usage from the CLI with auto-reload (watch mode)

To get granate restarted on every schema change install nodemon and use it as follows:

> npm i -g nodemon
> nodemon --exec granate serve todos.graphqls -a -- -e js,json,graphqls

[nodemon] 1.10.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `granate serve todos.graphqls -a -e js,json,graphqls`
Annotations: 'mock,rest' enabled.
Granate server listening on: 'http://localhost:4000/graphql'.

Usage as API

If you prefer to use granate as an API, install granate and graphql (peer dependency of granate) in your application with the following command and have a look at the tests to learn the API.

> npm i granate graphql --save

More examples

About

Granate container for annotated GraphQL

License:MIT License


Languages

Language:TypeScript 100.0%