使用 GraphiQL 或 GraphQL 端点生成 schema.json

Generate schema.json with GraphiQL or GraphQL endpoint

我在创建 schema.json 文件时遇到问题,该文件可以使用 babel-relay-plugin 进行解析而不会 运行 出错。看一下 schema.json file included in relay's example folder, I tried to copy the query in GraphiQL but I can't seem to get it right. I'm using Laravel 作为后端。这是我可以通过 GraphiQL 或向 GraphQL 端点发送请求并保存响应来完成的事情吗?

尝试解析 schema.json 文件时发生的错误:

Cannot read property 'reduce' of undefined while parsing file: /Users/username/Sites/Homestead/Code/ineedmg-graphql/resources/assets/js/app.js

上次使用 GraphiQL 的尝试:

{
  __schema {
    queryType { 
      name
    },
    types {
        kind,
        name,
        description,
        fields {
            name,
            description,
            type {
              name,
              kind,
              ofType {
                name
                description
              }
            }
            isDeprecated,
            deprecationReason,
        },
      inputFields {
        name
        description
      }
      interfaces {
        kind
        name
        description
      },
      enumValues {
        name
        description
        isDeprecated
        deprecationReason
      }
    },
    mutationType { 
      name
    },
    directives {
      name,
      description,
      onOperation,
      onFragment,
      onField,
      args {
        name
        description
        defaultValue
      }
    }
  }
}

是啊!如果您查看示例,您会发现它们通过执行查询生成了 schema.json 文件:https://github.com/relayjs/relay-starter-kit/blob/84da9351d100f97e6ed4f08bc70a893779e61c29/scripts/updateSchema.js#L11

这个查询实际上就是来自 graphql-js 的这个特定查询:https://github.com/graphql/graphql-js/blob/v0.4.12/src/utilities/introspectionQuery.js#L11-L89