0

I had a perfectly working relay modern app with 1.1.0 babel-plugin-relay + react-relay + react-compiler + graphql 0.10.x, react 15.5.x but since upgrading all of them to 1.4.1 and graphql to 0.11.7 and react to 16.0.0 I keep getting this error when running 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.

with babel-plugin-relay like so: 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
})

and webpack.config.js:

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

}

the question is why ? and how I can fix it? because in the response I can clearly see types:

can see relay types here

codepreneur
  • 446
  • 6
  • 18

1 Answers1

2

Solved it.

Had to change this:

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

to this:

module.exports = babelRelayPlugin(schema.data.__schema, {
  abortOnError: true
})
codepreneur
  • 446
  • 6
  • 18