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

csm*_*32s 7 reactjs graphql graphql-js relayjs

我在创建schema.json文件时遇到问题,该文件可以使用babel-relay-plugin进行解析,而不会遇到错误.看一下relay的example文件夹中包含的schema.json文件,我尝试在GraphiQL中复制查询,但我似乎无法正确使用它.我正在使用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
Run Code Online (Sandbox Code Playgroud)

最后一次尝试使用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
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

tai*_*ion 15

对!如果您查看示例,可以看到它们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.