从内省模式生成graphql typedef字符串

时间:2016-10-25 11:14:41

标签: graphql graphql-js

我有一个内省模式的结果JSON文件,有一个简单的方法:

  1. 使用graphql-js?
  2. 摄取
  3. 将其转换为typedef?
  4. 的字符串文字样式

    所以:

       {
         "data": {
           "__schema": {
             "queryType": {
               "name": "Query"
             },
             "types": {
             {
               "kind": "OBJECT",
               "name": "UserNode",
               "description": "",
               "fields": [
               {
                 "name": "firstName",
                 "description": "",
                 "args": [],
                 "type": {
                   "kind": "SCALAR",
                   "name": "String",
                   "ofType": null
                },
                "isDeprecated": false,
                "deprecationReason": null
              },
              ...
       }
    

    会变成:

       schema {
         query: Query
       }
    
       user {
         firstName: String
       }
       ...
    

1 个答案:

答案 0 :(得分:1)

如果您运行的是GraphQL服务器(而不仅仅是json架构),那么您可以使用Apollo的graphql-tools中的gqlschema执行此操作:

gqlschema http://localhost:3000/graphql -t

另见this question

相关问题