Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The @goExtraField directive violates the graphql spec #3145

Closed
vikstrous2 opened this issue Jun 17, 2024 · 3 comments · Fixed by #3150
Closed

The @goExtraField directive violates the graphql spec #3145

vikstrous2 opened this issue Jun 17, 2024 · 3 comments · Fixed by #3150

Comments

@vikstrous2
Copy link

What happened?

I ran a linter against a schema that uses the @goExtraField directive more than once for the same type.
I hit this error:

The directive "@goExtraField" can only be used once at this location. invalid-graphql-schema

Defined here: https://github.com/graphql/graphql-js/blob/75dca3dd18e5be3031416965049fbde48a5adb20/src/validation/rules/UniqueDirectivesPerLocationRule.ts
The graphql spec considers this invalid: https://spec.graphql.org/draft/#sec-Directives-Are-Unique-per-Location

What did you expect?

I expected it to pass

Minimal graphql.schema and models to reproduce

type User
	@goExtraField(
		name: "Session"
		type: "github.com/author/mypkg.Session"
		description: "A Session used by this user"
		overrideTags: "xml:\"session\""
	)
	@goExtraField(name: "Activated", type: "bool")
	@goExtraField(
		type: "time.Time"
		description: "type without name will be embedded"
	) {
	id: ID
	name: String
}

https://gqlgen.com/recipes/extra_fields/#:~:text=type%20User%0A%09%40goExtraField,%3A%20String%0A%7D

versions

n/a

@vikstrous2
Copy link
Author

One solution could be to add a new directive, goExtraFields, which takes a list of fields. I don't know if directives can take lists of objects though.

@alexandear
Copy link
Contributor

@vikstrous2, thank you for such a detailed issue description. You can add the repeatable keyword to the directive and the lint issue will be resolved.

Additionally, I fixed the example in gqlgen's docs in PR #3150.

@vikstrous2
Copy link
Author

Oh, wow. That was easy! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants