简体   繁体   中英

Relay Schema Cache not updating

I'm getting the following message in the developer console: "

Uncaught Error: GraphQL validation error. Cannot query field XXXX in YYYY.js. Try updating your GraphQL schema if an argument/field/type was recently added

I have already tried running npm start in order to update the schema. What am I doing wrong?

You may want to create a build function for your updating your client schema, and include a script within your package.json to run this automatically using nodemon.

This is the script that I use.

#!/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)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM