gpt4 book ai didi

javascript - BabelPluginRelay : Expected plugin context to include "types", 但得到 :[object Object] when upgrading from 1. 1.0 到 1.4.1。为什么?

转载 作者:行者123 更新时间:2023-12-01 02:53:03 25 4
gpt4 key购买 nike

我有一个完美工作的中继现代应用程序,带有 1.1.0 babel-plugin-relay + React-relay + React-compiler + graphql 0.10.x,react 15.5.x,但自从将它们全部升级到 1.4.1 和 graphql到 0.11.7 并响应 16.0.0 我在运行 npm start 时不断收到此错误:

ERROR in ./src/main.js
Module build failed: Error: BabelPluginRelay: Expected plugin context to include "types", but got:[object Object]
at BabelPluginRelay (/Users/johndoe/testing/atc/node_modules/babel-plugin-relay/lib/BabelPluginRelay.js:36:11)
at Object.<anonymous> (/Users/johndoe/testing/atc/src/babelRelayPlugin.js:28:18)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at /Users/johndoe/testing/atc/node_modules/babel-core/lib/transformation/file/options/option-manager.js:178:20
@ multi (webpack)-dev-server/client?http://localhost:3333 ./src/main.js
webpack: Failed to compile.

像这样使用 babel-plugin-relay :babelRelayPlugin.js:

const babelRelayPlugin = require('babel-plugin-relay')
const { introspectionQuery, buildClientSchema, printSchema } = require('graphql/utilities')
const request = require('sync-request')
const fs = require('fs')
const path = require('path')
const schemaPath = path.join(__dirname, 'schema');


const graphqlHubUrl = 'https://myhub.com/dev/graphql'

const response = request('POST', graphqlHubUrl, {
qs: {
query: introspectionQuery
}
})

console.log('response ', response)

const schema = JSON.parse(response.body.toString('utf-8'))

console.log('schema ', schema)
const graphQLSchema = buildClientSchema(schema.data);
fs.writeFileSync(
`${schemaPath}.graphql`,
printSchema(graphQLSchema)
);

module.exports = babelRelayPlugin(schema.data, {
abortOnError: true
})

和 webpack.config.js:

query: {
presets: ['env', 'react', 'stage-2'],
plugins: ['relay', 'transform-class-properties', __dirname + '/src/babelRelayPlugin']

}

问题是为什么?我该如何解决它?因为在响应中我可以清楚地看到类型:

can see relay types here

最佳答案

解决了。

必须改变这一点:

module.exports = babelRelayPlugin(schema.data, {
abortOnError: true
})

对此:

module.exports = babelRelayPlugin(schema.data.__schema, {
abortOnError: true
})

关于javascript - BabelPluginRelay : Expected plugin context to include "types", 但得到 :[object Object] when upgrading from 1. 1.0 到 1.4.1。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com