V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
timqian
10.02D

从 Graphql Schema 生成 Graphql query

  •  
  •   timqian ·
    timqian · Mar 27, 2018 · 3422 views
    This topic created in 2956 days ago, the information mentioned may be changed or developed.

    源码: https://github.com/timqian/gql-generator

    在为 graphql server 写 api test 的时候,每个 test 都需要手写 query。容易出现小错误,而且当 schema 有改变的时候,要去更新它们十分不便。

    事实上,query 长什么样应该可以从 schema 里生成出来。

    于是有了这个小工具

    # Sample schema
    type Query {
        user(id: Int!): User!
    }
    
    type User {
        id: Int!
        username: String!
        email: String!
        createdAt: String!
    }
    
    # Sample query generated
    query user($id: Int!) {
        user(id: $id){
            id
            username
            email
            createdAt
        }
    }
    

    具体介绍及使用方法见 github: https://github.com/timqian/gql-generator

    Supplement 1  ·  Oct 19, 2018
    更新了文档和代码
    1 replies    2018-10-19 12:37:19 +08:00
    470326964
        1
    470326964  
       Oct 19, 2018
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5100 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 09:10 · PVG 17:10 · LAX 02:10 · JFK 05:10
    ♥ Do have faith in what you're doing.