oneqljs / oneQL

简单、轻量的 Nodejs服务端 Graphql 渐进式解决方案

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oneQL

Use koa + apollo-server-koa
book: (https://oneqljs.github.io/oneQL/book/)

npm node Downloads GitHub license

Getting Started

  • npm install oneql-init -g
  • oneql-init project
  • cd project && npm install && npm run dev

Init oneQL (oneql-init create boilerplate)

// src/index.ts
import oneql from 'oneql'

import typeDefs from './types'
import resolvers from './resolvers'

new oneql({
    schema: {
        typeDefs,
        resolvers
    },
    context: async ({ ctx }) => {
        return {
            ctx
        }
    }
})

Example:

query db($key: String, $ext: [ExtensionType]){
  hello
  city(request: {key: $key,  ext: $ext } ) {
    datainfo{
      CountryId
      country
      type
    }
  }
}
QUERY VARIABLES
{"key":"D", "ext": [{ "key":"2", "value":"1"}] }

avatar

query simple{
  seatSimple {
    resultList{
      fInfo{
        fNo
      }
    }
  }
}

开发建议

  • 一个请求可以带多个schema,对应请求逻辑是resolvers文件夹下index.js, connect所有resolvers
  • 每一个最外层schema分一个对应的types文件和一个resolvers文件
  • types文件夹下index.js , connect所有types
  • 每一个schema具体数据实现,如果涉及请求,建议api文件夹里建一个文件处理逻辑

Util

  • util提供了soa请求封装,如自动处理埋点信息;
  • 提供xconfig集成;
  • 提供redis方法集成
  • 提供log方法集成

Production Environment

  • close graphlQL playground
  • app.config.js, env=prod // close
const server = new ApolloServer({
  typeDefs,
  // mocks
  resolvers
  // playground: false  // false为关闭
})

Mind map

avatar

License

MIT

About

简单、轻量的 Nodejs服务端 Graphql 渐进式解决方案


Languages

Language:TypeScript 88.9%Language:JavaScript 11.1%