登录
首页 >  Golang >  Go问答

如何解决 gqlgen 中的“获取架构时出错”

来源:stackoverflow

时间:2024-04-08 16:57:34 168浏览 收藏

知识点掌握了,还需要不断练习才能熟练运用。下面golang学习网给大家带来一个Golang开发实战,手把手教大家学习《如何解决 gqlgen 中的“获取架构时出错”》,在实现功能的过程中也带大家重新温习相关知识点,温故而知新,回头看看说不定又有不一样的感悟!

问题内容

美好的一天,我是 go 新手,我正在尝试使用 go 构建一个 graphql 服务,我使用 go gqlgen 包做到了这一点。现在,当在初始启动时安装并生成必要的文件时,我可以在文档选项卡上看到默认的 todo 架构和解析器,当我实现或向架构文件添加其他架构时,我从演示中得到“错误获取架构” p>

我的架构文件:

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 }

请我需要帮助,谢谢..


正确答案


预计 type mutation,您应该将 type query (至少一种方法)添加到您的 .graphql 文件中。例如,您可以将其添加到 schema.graphql 中:

type Query {
   foo(bar: String!): String!
}

之后,使用gqlgen cli 生成代表新.graphql 架构的新go 文件。

今天关于《如何解决 gqlgen 中的“获取架构时出错”》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>