Code Monkey home page Code Monkey logo

oneql's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.