【问题标题】:generate graphql typedef string from introspected schema从自省模式生成 graphql typedef 字符串
【发布时间】:2017-03-07 09:57:46
【问题描述】:

我有一个自省模式的 JSON 文件,有没有简单的方法:

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

所以:

   {
     "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
   }
   ...

【问题讨论】:

    标签: graphql graphql-js


    【解决方案1】:

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

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

    另见this question

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2020-12-05
      • 2023-04-01
      • 2020-01-15
      • 1970-01-01
      • 2020-11-13
      • 2010-12-28
      • 2019-04-20
      • 2017-04-14
      相关资源
      最近更新 更多