你好,我是go的新手,我正在尝试用go构建一个graphql服务,我使用go gqlgen包做到了这一点。现在,当安装和生成必要的文件时,我可以在docs选项卡上看到默认的TODO模式和解析器,当我实现或添加其他模式到模式文件时,我会从playground
中获得“Error fetching schema”
我的架构文件:
scalar Timestamp
type User {
id: ID!
email: String!
password: String!
otp_code: String!
role: String!
status: String!
isEmailVerified: Boolean!
otp_expire_time: Timestamp!
createdAt: Timestamp!
updatedAt: Timestamp!
deletedAt: Timestamp!
}
input LoginCredential {
email: String!
password: String!
}
input UserSignUpDetail {
email: String!
password: String!
}
type AuthResponse {
access_token: String!
refresh_token: String!
}
type Mutation {
UserLogin(input: LoginCredential!): AuthResponse!
UserSignUp(input: UserSignUpDetail!): User!
}
架构解析程序文件:
package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"fmt"
"gatewayservice/graph/generated"
"gatewayservice/graph/model"
)
// UserLogin is the resolver for the UserLogin field.
func (r *mutationResolver) UserLogin(ctx context.Context, input model.LoginCredential) (*model.AuthResponse, error) {
panic(fmt.Errorf("not implemented: UserLogin - UserLogin"))
}
// UserSignUp is the resolver for the UserSignUp field.
func (r *mutationResolver) UserSignUp(ctx context.Context, input model.UserSignUpDetail) (*model.User, error) {
panic(fmt.Errorf("not implemented: UserSignUp - UserSignUp"))
}
// Mutation returns generated.MutationResolver implementation.
func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
type mutationResolver struct{ *Resolver }
我需要帮助,谢谢。
1条答案
按热度按时间mwyxok5s1#
除了
type Mutation
之外,您应该将type Query
(至少一个方法)添加到 .graphql 文件中。例如,您可以将以下内容添加到schema.graphql
:之后,使用 gqlgen CLI生成新的Go文件,这些文件将表示新的 .graphql 模式。