0.1.1 • Published 2 years ago

gql-data-cog-tooth v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

FEATRUES

  • 字段计算
  • 图表数据
  • 数据聚合
  • 逻辑编排

USAGE

npm i gql-data-cog-tooth -S

schema规范(如果要用到FEATRUES)

  • 数据模型 Data 结尾
  • 查询结果 Result 结果
  • Result 内默认要有 list 其他按需要加 如chart

    extends 是自己扩展的语法糖 不是原生gql schema

type FooData extends Calc {

}

type FooResult {
    list(groupKey: String, ...dateArgs): [FooData]
    chart(groupKey: String, ...dateArgs): FooDataChart
    ...calc(on: String): FooData
}

resolve 规范

通过bindFeat 注入 特性

import { FEATS, bindFeats }  from 'gql-data-cog-tooth'
const {calc,chart, page,mutation} = FEATS;

const domain = 'Foo'

module.exports = {
  ...bindFeats({
    Query: {
      [domain]:_=>_
    },
    [domain+'Result']: {},
    [domain+'Data']: {},
    Mutation: {
          ["upsert" + domain]: (_) => _,
    },
}, {calc, chart, page, mutation})
}

connector 规范

common 需实现的部分

import {ConnectorBase}  from  'gql-data-cog-tooth';

export default class ConnectorBaseMix extends ConnectorBase {
  constructor(ctx) {
    super(ctx)
  }

  async getData(args) {
    //TODO
  }

  async getCalcData(params, groupKey, fields, type) {
    //TODO

  }

  async getGroupData(params, groupKey, fields, type="sum") {
    //TODO
    
  } 

}
import ConnectorMix from '../common'

class Connector extends ConnectorMix {
    constructor(ctx) {
      super(ctx)  
      this.serviceName = 'foo';
      this.queryCache = _ => [false];
      this.filterMap = {};
  }
   query(args) {
     return args
   }
}
  
module.exports = Connector;
  

QUERY

查询方式详见 ata

工程化

package.json

    "scripts": {
      "clean:gql": "rm -rf ./output/* ",
      "gen:gql": "npm run clean:gql && gql gen"
    },

config.gql.json

{
  "type": "Foo",
  "fetch": {
    "table": "foo",
    "api": "http://localhost:7001/genSchema/mysql?table="
  },
  "resolve": true,
  "connector": true,
  "link": null,
  "feats": ["calc", "chart", "page","mutation"]
}
0.1.0

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago