1

我正在关注Relay 101:构建黑客新闻客户端教程。

但在这个过程中我得到了错误

AssertionError: relay-101/index.js: getBabelRelayPlugin():
Expected schema to be an object with a `__schema` property.
at getSchema (/Users/ruseel/p/spike/relay-101/node_modules/babel-relay-plugin/src/getBabelRelayPlugin.js:224:3)
at NodePath.Plugin.visitor.TaggedTemplateExpression (/Users/ruseel/p/spike/relay-101/node_modules/babel-relay-plugin/src/getBabelRelayPlugin.js:104:26)
...

经过一番挖掘(getBabelRelayPlugin.js 中的 console.log),我注意到getBabelRelayPlugin.js中的 introspection var

   const introspection = typeof schemaProvider === 'function' ?
    schemaProvider() :
    schemaProvider;

是这样的。

{"errors":[{"message":"Must provide query string."}]}

但我不知道为什么会这样?为什么会发生此错误?

任何方向将不胜感激。

4

1 回答 1

0

我在 babelRelayPlugin.jstrospectionQuery 而不是 introspectionQuery 中打错了字。

var babelRelayPlugin = require('babel-relay-plugin');
var introspectionQuery = require('graphql/utilities').introspectionQuery;
var request = require('sync-request');

var graphqlHubUrl = 'http://www.graphqlhub.com/graphql';
var response = request('GET', graphqlHubUrl, {
  qs: {
    query: introspectionQuery
  }
});
于 2016-01-24T16:03:50.143 回答