reactjs - 使用 GraphQL 或 GraphQL 端点生成 schema.json

标签 reactjs graphql relayjs graphql-js

我在创建 schema.json 文件时遇到问题,该文件可以使用 babel-relay-plugin 进行解析而不会出现错误。看看schema.json文件包含在中继的示例文件夹中,我尝试在 GraphiQL 中复制查询,但我似乎无法正确执行。我正在使用Laravel作为后端。我可以通过 GraphQL 或向 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 .

关于reactjs - 使用 GraphQL 或 GraphQL 端点生成 schema.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33509643/

相关文章:

python - 如何在python graphene中处理带参数的查询

javascript - 中继片段变量

reactjs - 将客户端和服务器部署到同一个虚拟机

javascript - 尝试在 reactjs 中通过 document.getgetElementsByTagName 进行映射

css - 在 div 中居中对齐 Paper 组件

relayjs - 在中继请求中发送Cookie头字段

relayjs - 将变量传递给现代中继中的片段容器

javascript - Promise { <state> : "pending" } - Should we use . 那么在 async/await 之后?使困惑

graphql - 如何在 Cypress 中为特定的 GraphQL 请求设置别名?

c# - 使用和配置来自 .Net C# 控制台应用程序客户端的 Graphql 请求