Go语言 如何解决gqlgen中的“获取模式时出错”

d7v8vwbk  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(134)

你好,我是go的新手,我正在尝试用go构建一个graphql服务,我使用go gqlgen包做到了这一点。现在,当安装和生成必要的文件时,我可以在docs选项卡上看到默认的TODO模式和解析器,当我实现或添加其他模式到模式文件时,我会从playground

中获得“Error fetching schema”
我的架构文件:

  1. scalar Timestamp
  2. type User {
  3. id: ID!
  4. email: String!
  5. password: String!
  6. otp_code: String!
  7. role: String!
  8. status: String!
  9. isEmailVerified: Boolean!
  10. otp_expire_time: Timestamp!
  11. createdAt: Timestamp!
  12. updatedAt: Timestamp!
  13. deletedAt: Timestamp!
  14. }
  15. input LoginCredential {
  16. email: String!
  17. password: String!
  18. }
  19. input UserSignUpDetail {
  20. email: String!
  21. password: String!
  22. }
  23. type AuthResponse {
  24. access_token: String!
  25. refresh_token: String!
  26. }
  27. type Mutation {
  28. UserLogin(input: LoginCredential!): AuthResponse!
  29. UserSignUp(input: UserSignUpDetail!): User!
  30. }

架构解析程序文件:

  1. package graph
  2. // This file will be automatically regenerated based on the schema, any resolver implementations
  3. // will be copied through when generating and any unknown code will be moved to the end.
  4. import (
  5. "context"
  6. "fmt"
  7. "gatewayservice/graph/generated"
  8. "gatewayservice/graph/model"
  9. )
  10. // UserLogin is the resolver for the UserLogin field.
  11. func (r *mutationResolver) UserLogin(ctx context.Context, input model.LoginCredential) (*model.AuthResponse, error) {
  12. panic(fmt.Errorf("not implemented: UserLogin - UserLogin"))
  13. }
  14. // UserSignUp is the resolver for the UserSignUp field.
  15. func (r *mutationResolver) UserSignUp(ctx context.Context, input model.UserSignUpDetail) (*model.User, error) {
  16. panic(fmt.Errorf("not implemented: UserSignUp - UserSignUp"))
  17. }
  18. // Mutation returns generated.MutationResolver implementation.
  19. func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} }
  20. type mutationResolver struct{ *Resolver }

我需要帮助,谢谢。

mwyxok5s

mwyxok5s1#

除了type Mutation之外,您应该将type Query(至少一个方法)添加到 .graphql 文件中。例如,您可以将以下内容添加到schema.graphql

  1. type Query {
  2. foo(bar: String!): String!
  3. }

之后,使用 gqlgen CLI生成新的Go文件,这些文件将表示新的 .graphql 模式。

相关问题