我正在尝试在一个简单的 GraphQL 服务器上使用https://github.com/shurcooL/graphql GraphQL 客户端,我开始按照https://github.com/apollographql/apollo-server#installation-standalone上的代码片段进行操作:const { ApolloServer, gql } = require('apollo-server');// The GraphQL schemaconst typeDefs = gql` type Query { "A simple type for getting started!" hello: String }`;// A map of functions which return data for the schema.const resolvers = { Query: { hello: () => 'world', },};const server = new ApolloServer({ typeDefs, resolvers,});server.listen().then(({ url }) => { console.log(`🚀 Server ready at ${url}`);});我尝试将其与以下 Go 脚本一起使用:package mainimport ( "context" "fmt" "log" "github.com/shurcooL/graphql")var query struct { hello graphql.String}func main() { client := graphql.NewClient("http://localhost:4000", nil) if err := client.Query(context.Background(), &query, nil); err != nil { log.Fatal(err) } fmt.Printf("%+v\n", query)}但是,如果我尝试运行它,我会收到以下错误:2019/11/21 12:07:21 struct field for "hello" doesn't exist in any of 1 places to unmarshalexit status 1知道是什么原因造成的吗?
1 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
hello
不是导出名称,我需要将其更改为Hello
:
var query struct { Hello graphql.String }
现在程序打印
{Hello:world}
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消