亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go GraphQL 客戶端應用于“hello world”GraphQL 服務器:

Go GraphQL 客戶端應用于“hello world”GraphQL 服務器:

Go
梵蒂岡之花 2023-08-07 11:22:51
我正在嘗試在一個簡單的 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}


查看完整回答
反對 回復 2023-08-07
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號