apollo android对表示graphql的请求总是导致http 400
当通过apollo graphQL提交到express graphQL Web应用程序时,我在如何使最基本的graphQL正常工作方面遇到了问题。通过graphiql的web请求,一切正常。只要我尝试使用apollo android客户端,无论我尝试什么,我都会收到400个错误 我的android依赖性是:apollo android对表示graphql的请求总是导致http 400,android,express,graphql,apollo-android,Android,Express,Graphql,Apollo Android,当通过apollo graphQL提交到express graphQL Web应用程序时,我在如何使最基本的graphQL正常工作方面遇到了问题。通过graphiql的web请求,一切正常。只要我尝试使用apollo android客户端,无论我尝试什么,我都会收到400个错误 我的android依赖性是: apollo:apollo运行时:2.3.1 我的节点依赖项: 快递:4.17.1 快速图形QL:^0.11.0 graphql:^15.3.0 我的基本服务器是: const ex
- apollo:apollo运行时:2.3.1
- 快递:4.17.1
- 快速图形QL:^0.11.0
- graphql:^15.3.0
const express = require('express')
const { graphqlHTTP } = require('express-graphql')
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLNonNull
} = require ('graphql')
const RootQueryType = new GraphQLObjectType({
name: 'Query',
description: 'Root query',
fields: () => ({
hello: {
type: GraphQLString,
resolve() {
return 'world'
}
},
})
})
const schema = new GraphQLSchema({
query: RootQueryType
})
const app = express()
app.use('/graphql', function (req, res, next) {
console.log("We got a request!: " + req.ip)
next();
},
graphqlHTTP ({
schema: schema,
graphiql: true
}))
app.listen(5000, () => console.log('server running'))
通过graphiQL提交请求,我只是请求“{hello}”,并获得成功响应:
{
"data": {
"hello": "world"
}
}
我使用DownloadApolloadSchema任务生成了我的android模式文件,我的graphiql内容如下:
query hello() {
hello()
}
我的主要活动是onCreate():
这让我发疯,因为我似乎无法深入研究400错误,也不知道这为什么如此困难。我已经通过模拟器和实际设备尝试了这个请求。结果没有明显变化,因为是服务器抛出了错误。希望这是一个简单的错误 经过几个小时的挖掘,试图让wireshark阅读完整的请求/响应等,我终于让它开始工作了。原来我的.graphql定义文件名为“Hello.graphql”。如上所述,取自其他示例的内容为:
query hello() {
hello()
}
我试图删除多余的paren,但没有效果,我还试图更改大写字母,但没有效果。有一件事我错过了,那就是最后的修复是删除paren并更改大写。。。最终工作定义文件内容:
query Hello {
hello
}
为什么不使用相同的查询?不需要args,不需要大括号。。。IDK android但与文档示例相比,为什么
HelloQuery.builder().build()
,而不仅仅是newhelloquery()
。。。原始网络请求/正文看起来如何?这是满足生成器脚本的唯一方法。这里有一个等效的示例:声明HelloQuery的新实例会导致相同的错误,并且不允许您为查询参数传递变量。不幸的是,我还没能找到一种方法从express获得关于400的任何其他详细信息;我尝试的每件事都会给我相同的堆栈,带有相同的通用“400”错误。此查询不需要参数-“new”语法,如果没有第一个“Hello”,它应该可以工作。。。“操作名称”可以是未定义的
query hello() {
hello()
}
query Hello {
hello
}