RecifeJs

RecifeJs

  • Docs
  • Blog
  • Github

›Concepts Basics

RecifeJs

  • About
  • Philosophy
  • Contribution

Getting Started

  • Installation
  • Settings

Concepts Basics

  • Controllers
  • Decorators
  • Middlewares
  • Models
  • Plugins
  • Scalars
  • Validators

CLI

  • Introduction
  • Create Structures

Controllers

The controllers are part of the MVC(model–view–controller) architectural pattern, being responsible for receive user requests and controlling the use of models and views. In RecifeJs the controllers will also be used to assemble the graphql schemes.

Creating Controller

Use the CLI for create a new controller:

recife controller User

or

npx recife-cli controller User


The controller will be created in the src/controllers directory with the name UserController.ts. And it will have the following content:

import { Query, Mutation } from "recife";

class UserController {
  constructor() {
    //
  }
}

export default UserController;

Using the GraphQL

RecifeJs uses decorators to identify the methods of the controllers that will represent the graphql schemes. See more about decorators here.

See the example below:

import { Query, Mutation } from "recife";
import UserModel from "../models/UserModel";

class UserController {
  constructor() {
    //
  }

  @Query()
  async getUser(): UserModel {
    return await UserModel.findOne();
  }
}

export default UserController;

From this method, the GraphQL schema will be created. See how the query looks:

extend type Query {
  getUser: User!
}

Parameters

to do

Values not required

to do

Last updated on 6/22/2020 by André Lins
← PreviousDecorators →
  • Creating Controller
  • Using the GraphQL
    • Parameters
    • Values not required
RecifeJs

Docs

Getting StartedCLIPhilosophy

Community

User ShowcaseProject ChatBlogGitHubStar
Copyright © 2020 RecifeJs