2017-10-20 86 views
0

我有一个完美的工作中继现代应用1.1.0 babel插件继电器+ react-relay + react-compiler + graphql 0.10.x,反应15.5.x,但自从升级所有1.4.1和graphql到0.12.2和反应16.0.0运行NPM开始时,我不断收到此错误:BabelPluginRelay:期望插件上下文包含“类型”,但在从1.1.0升级到1.4.1时得到了:[object Object]。为什么?

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. 

与巴贝尔-插件继电器像这样: 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

回答

0

解决它。

不得不改变这一点:

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

这样:

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