0.1.6 • Published 1 year ago

graphql-monster-builder v0.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

GraphQL Monster Builder

Build server with CRUD with GraphQL and Rest API interface. With these features:

  • Generate server base on simple schema file
  • Integrated authentication to secure models with pre-defined rules
  • Hooks to customize the server to your needs without breaking (re)build process
  • Integrated GraphQL documentation and Swagger for Rest API
  • Prepared CRA templates for easy connect to React App (ES6 or Typescipt)

Usage

$ graphql-monster-builder <operation> <schema> <outdir>

Example

Example of simple todo server. Create Schema File file with name todo.schema and folowing content in your local directory.

Note: Be sure on your system is running instance of MongoDB

@all(filter:"user_every.id={{userId}}")
@create("public") @one("public") @update("public") @remove("public")
type Todo @model {
  message: String
  done: Boolean @default(false)
}

Then run these command to actual create graphql-monster-server to directory with name todo-server

npx graphql-monster-builder --backend todo.schema todo-server

# or

npm i -g graphql-monster-builder
graphql-monster-builder --backend todo.schema todo-server

Now you should just move to todo-server directory and run generated server

cd todo-server/ && yarn && yarn start

Now you can check the:

GraphQL

Here is some examples with GraphQL mutations over Todo model Image of graphql Here is some examples with GraphQL mutations over Todo model Image of graphql

Rest API

The same can be acomplish with Rest API what is documented by Swagger Image of swagger

Documentation

For more about schema definition, please visit our documentation:

Explain create modesls and CRUD with GraphQL Monster

You can check video how to create models on www.graphql.monster platform

Hooks

During project development You will probably very often updating the schema (adding new models or updating existing or maybe changing the protecting rules). To customize server functionality is a option of adding a hook. Hooks can be of this two type:

  • before
  • after

and can have handle these actions:

  • One (read one item)
  • All (read all items)
  • My (read all my items)
  • Create (create one item)
  • Update (update one item)
  • Delete (delete one item)

Hooks are setlet in file entryHooks.ts in services/ with export object hooks with your defined overrides

// example of `service/entryHooks.ts`

export const hooks = {
    services: {
        beforeTodoCreate: async (entry, todo) => {
            // do some action before Todo is stored into DB
            todo.data.message = `Created Todo: ${todo.data.message}`
            return todo.data
        },
        beforeTodoUpdate: async (entry, todo) => {
            // do some action before Todo is updated in DB
            todo.data.message = `Updated Todo: ${todo.data.message}`
            return todo.data
        },
        afterTodoCreate: async (entry, todo) => {
            // do some action after Todo is updated in DB
            return todo.data
        },
        afterTodoCreate: async (entry, todo) => {
            // do some action after Todo is updated in DB
            return todo.data
        },
    },
}

Note: what is in gen/ is have fully on control the builder generator, so what ever you will change will be in next (re)build lost!

Contain

0.1.4

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago