我正在嘗試在一個(gè)簡(jiǎn)單的 GraphQL 服務(wù)器上使用https://github.com/shurcooL/graphql GraphQL 客戶端,我開(kāi)始按照https://github.com/apollographql/apollo-server#installation-standalone上的代碼片段進(jìn)行操作: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)}但是,如果我嘗試運(yùn)行它,我會(huì)收到以下錯(cuò)誤:2019/11/21 12:07:21 struct field for "hello" doesn't exist in any of 1 places to unmarshalexit status 1知道是什么原因造成的嗎?
1 回答

守候你守候我
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊
hello
不是導(dǎo)出名稱,我需要將其更改為Hello
:
var?query?struct?{ ????Hello?graphql.String }
現(xiàn)在程序打印
{Hello:world}
- 1 回答
- 0 關(guān)注
- 140 瀏覽
添加回答
舉報(bào)
0/150
提交
取消