egg icon indicating copy to clipboard operation
egg copied to clipboard

About Middleware of egg-graphql with node

Open my9074 opened this issue 7 years ago • 2 comments

Hello, Egg-graphql currently support middleware of node solution ? Our node server only make data conversion, and through the Restful API communication with backend ( java / go .etc ).We want to make a layer of encapsulation in the middleware through egg-graphql, the backend still maintains the form of Restful API

my9074 avatar Feb 07 '18 11:02 my9074

It's ok, you can put the Restful API in your app.service, then call them by graphql connector

example


'use strict';
class ArticleConnector {
    constructor(ctx) {
        this.ctx = ctx;
    }
    async getArticleInfoByService(iArticleID) {
        return await this.ctx.service.article.getArticleByID(iArticleID); // your restful api here
    }
  }
module.exports = ArticleConnector;

jtyjty99999 avatar Feb 08 '18 02:02 jtyjty99999

@jtyjty99999 Thx~ In other words, egg-graphql passes the CRUD operations to the restful api ?

my9074 avatar Feb 08 '18 06:02 my9074