【问题标题】:Relay Schema Cache not updating中继架构缓​​存未更新
【发布时间】:2017-02-23 05:52:08
【问题描述】:

我在开发者控制台中收到以下消息:“

未捕获的错误:GraphQL 验证错误。 Cannot query field XXXX in YYYY.js. 如果有参数/字段/类型,请尝试更新您的 GraphQL 架构 最近添加了

我已经尝试运行 npm start 以更新架构。我做错了什么?

【问题讨论】:

  • 你能分享一下查询和架构吗?没有这个很难说。
  • 据我所知,这是一个更新问题,与实际架构和查询无关

标签: reactjs graphql relayjs


【解决方案1】:

您可能想要创建一个构建函数来更新您的客户端架构,并在您的 package.json 中包含一个脚本以使用 nodemon 自动运行它。

这是我使用的脚本。

#!/usr/bin/env babel-node --optional es7.asyncFunctions

import fs from 'fs'
import path from 'path'
import Schema from './schema.js'
import touch from 'touch'

import { graphql }  from 'graphql'
import { introspectionQuery, printSchema } from 'graphql/utilities'

const p = '../../../client/schema-build/schema.json';

// Save JSON of full schema introspection for Babel Relay Plugin to use
(async () => {
  var result = await (graphql(Schema, introspectionQuery))
  if (result.errors) {
    console.error(
      'ERROR introspecting schema: ',
      JSON.stringify(result.errors, null, 2)
    )
  } else {
    fs.writeFileSync(
      path.join(__dirname, p),
      JSON.stringify(result, null, 2)
    )

    touch('../../../client/index.js', {}, () => {
      process.exit(0)
    })
  }
})()

// Save user readable type system shorthand of schema
fs.writeFileSync(
  path.join(__dirname, p),
  printSchema(Schema)
)

【讨论】:

    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    相关资源
    最近更新 更多