空白的GraphQL查询应该返回什么?

时间:2017-05-31 06:15:59

标签: graphql graphiql

我正在尝试构建GraphQL服务器,并尝试使用GraphiQL Chrome扩展程序来进行游戏。

只要我将端点设置为我的服务器http://localhost:3000/graphql,GraphiQL就会发送一个空查询:

Request URL:http://localhost:3000/graphql
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:3000
Referrer Policy:no-referrer-when-downgrade

我让它返回一个空响应,但是,我在Chrome中遇到了这个JavaScript错误:

react.min.js:14 Uncaught TypeError: Cannot read property 'length' of undefined
    at GraphiQL.autoCompleteLeafs (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/graphiql/graphiql.js:1060:33)
    at GraphiQL._runEditorQuery (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/graphiql/graphiql.js:1131:13)
    at Object.r (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:14:10134)
    at i (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:12:21911)
    at Object.u [as executeDispatchesInOrder] (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:12:22122)
    at p (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:12:18475)
    at f (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:12:18601)
    at Array.forEach (native)
    at r (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:15:26156)
    at Object.processEventQueue (chrome-extension://fkkiamalmpiidkljmicmjfbieiclmeij/ext/react.min.js:12:19721)


之后,GraphiQL根本不起作用。我可以输入任何查询,单击播放按钮,它所做的只是重复错误:

enter image description here      我错过了什么? GraphiQL是否期望从空白查询中获得某种模式?

1 个答案:

答案 0 :(得分:1)

我相信GraphiQL chrome扩展需要来自API的对象响应。尝试在emtpy请求中返回一个空白对象,看看是否能解决它。

在提交空白请求时查看https://launchpad.graphql.com(也使用GraphiQL),我得到以下对象:

{
  "code": 400,
  "error": "Script returned an error.",
  "details": "No query was provided in request body."
}

这是一个可用于调试的描述性响应。