我正在尝试在一个简单的 GraphQL 服务器上使用https://github.com/shurcooL/graphql GraphQL 客户端,我开始按照https://github.com/apollographql/apollo-server#installation-standalone上的代码片段进行操作:
const { ApolloServer, gql } = require('apollo-server');
// The GraphQL schema
const 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 main
import (
"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 unmarshal
exit status 1
知道是什么原因造成的吗?
守候你守候我
相关分类