Resolver.ModuleName返回的参数太多了。

huangapple go评论77阅读模式
英文:

too many parameters returned by Resolver.ModuleName

问题

我正在将单体架构拆分为微服务架构。
我已经这样做了,但是当我在当前代码库中构建代码时,出现了以下错误。

我们使用graphql-gophers库

panic: (Resolver).Dummy返回的参数过多

有人在使用golang进行graphql查询时见过这个错误吗?

尝试了很多方法,但都没有成功。

任何帮助将不胜感激。

英文:

I am working on breaking the monolithic architecture into Microservice architecture.
I did that but when I am building the code in my current repository I am getting this error.

We use graphql-gophers library

panic: too many parameters returned by (Resolver).Dummy

Has anyone ever seen this error in golang using graphql for querying?

Tried so many things but nothing has worked.

Any help would be appreciated

答案1

得分: 0

错误消息来自graph-gophers/graphql-go internal/exec/resolvable/resolvable.go#makeFieldExec

当解析的模式与现有结构的字段不匹配时,会调用该函数。

example/customerrors/starwars.go中的示例中,每个字段都匹配,不会触发错误消息:

var Schema = `
	schema {
		query: Query
	}
	type Query {
		droid(id: ID!): Droid!
	}
	# An autonomous mechanical character in the Star Wars universe
	type Droid {
		# The ID of the droid
		id: ID!
		# What others call this droid
		name: String!
	}
`

type droid struct {
	ID   graphql.ID
	Name string
}

其解析器使用了正确的参数:

type Resolver struct{}

func (r *Resolver) Droid(args struct{ ID graphql.ID }) (*droidResolver, error) {
	if d := droidData[args.ID]; d != nil {
		return &droidResolver{d: d}, nil
	}
	return nil, &droidNotFoundError{Code: "NotFound", Message: "This is not the droid you are looking for"}
}

尝试使用该示例检查是否正常工作,然后根据自己的代码进行修改。

英文:

The error message comes from graph-gophers/graphql-go internal/exec/resolvable/resolvable.go#makeFieldExec

It is called when you parse a schema which does not match the field of an existing struct.

The one illustrated in example/customerrors/starwars.go does match every field and would not trigger the error message:

var Schema = `
	schema {
		query: Query
	}
	type Query {
		droid(id: ID!): Droid!
	}
	# An autonomous mechanical character in the Star Wars universe
	type Droid {
		# The ID of the droid
		id: ID!
		# What others call this droid
		name: String!
	}
`

type droid struct {
	ID   graphql.ID
	Name string
}

Its resolver does use the right parameters:

type Resolver struct{}

func (r *Resolver) Droid(args struct{ ID graphql.ID }) (*droidResolver, error) {
	if d := droidData[args.ID]; d != nil {
		return &droidResolver{d: d}, nil
	}
	return nil, &droidNotFoundError{Code: "NotFound", Message: "This is not the droid you are looking for"}
}

Try and use that example to check it does work, then modify it to transition to your own code.

huangapple
  • 本文由 发表于 2022年1月17日 14:05:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/70737133.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定