我正在嘗試在一個簡單的 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 關注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消