Skip to content

Update gqlparser v2 to v2.5.22 to Support @oneOf and @deprecated on input values#3507

Merged
StevenACoffman merged 4 commits intomasterfrom
update_gqlparser_v2_v2_5_22
Jan 27, 2025
Merged

Update gqlparser v2 to v2.5.22 to Support @oneOf and @deprecated on input values#3507
StevenACoffman merged 4 commits intomasterfrom
update_gqlparser_v2_v2_5_22

Conversation

@StevenACoffman
Copy link
Copy Markdown
Collaborator

@StevenACoffman StevenACoffman commented Jan 27, 2025

Solved: Support @oneOf and @deprecated on input values

Some folks (e.g. @CodingContraption ) ran into a problem recently with graphql-protect by @ldebruijn when used to protect an apollo-router GraphQL API.

The latest apollo-router supports a draft version of the GraphQL spec and that draft adds support for deprecated input values: graphql/graphql-spec#805

gqlparser v2.5.1 support was still at an earlier version of the GraphQL spec, resulting in errors when a client requests introspection fields like isDeprecated and deprecationReason on the __InputValue.

To fix this, in the gqlparser prelude.graphql was updated to match the draft introspection schema and the reference graphql-js implementation. This included a few updated validation rules. This was done in vektah/gqlparser#342 and
then github.com/vektah/gqlparser/v2 v2.5.2 was released, but now when updating gqlparser in gqlgen, I am finding a number of problems.

The last time there was a major GraphQL spec version support bump in gqlparser, gqlgen required some modifications #1982 so it may be that we need some modifications here in gqlgen, or it may be we need some tweaks to gqlparser or maybe both.


In this particular case, it looks like the gqlparser change is currently causing the generated ResolverRoot interface go from this:

type ResolverRoot interface {
	Mutation() MutationResolver
	Query() QueryResolver
	Subscription() SubscriptionResolver
}

To this:

type ResolverRoot interface {
	Mutation() MutationResolver
	Query() QueryResolver
	Subscription() SubscriptionResolver
	__InputValue() __InputValueResolver
	__Type() __TypeResolver
}

Which is causing this problem:

cannot use &resolver{…} (value of type *resolver) as ResolverRoot value in struct literal: *resolver does not implement ResolverRoot (missing method __InputValue)

This now looks like:

type Stub struct {
	QueryResolver struct {
		EchoIntToInt                func(ctx context.Context, n *int32) (int32, error)
		EchoInt64ToInt64            func(ctx context.Context, n *int) (int, error)
		EchoIntInputToIntObject     func(ctx context.Context, input Input) (*Result, error)
		EchoInt64InputToInt64Object func(ctx context.Context, input Input64) (*Result64, error)
	}
	__InputValueResolver struct {
		IsDeprecated      func(ctx context.Context, obj *introspection.InputValue) (bool, error)
		DeprecationReason func(ctx context.Context, obj *introspection.InputValue) (*string, error)
	}
	__TypeResolver struct {
		IsOneOf func(ctx context.Context, obj *introspection.Type) (*bool, error)
	}
}

Adding IsDeprecated was last touched in #455 so that might provide a model for how to support these changes.


Updated: Ok, it looks like it was pretty straightforward after all, following those two prior PR examples.

Signed-off-by: Steve Coffman steve@khanacademy.org

Signed-off-by: Steve Coffman <steve@khanacademy.org>
@StevenACoffman StevenACoffman added the help wanted Extra attention is needed label Jan 27, 2025
@StevenACoffman StevenACoffman changed the title Update gqlparser v2 to v2.5.22 Update gqlparser v2 to v2.5.22 to Support @oneOf and @deprecated on input values Jan 27, 2025
Signed-off-by: Steve Coffman <steve@khanacademy.org>
Signed-off-by: Steve Coffman <steve@khanacademy.org>
Signed-off-by: Steve Coffman <steve@khanacademy.org>
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 27, 2025

Coverage Status

coverage: 73.738% (-0.2%) from 73.891%
when pulling 9ff0e2d on update_gqlparser_v2_v2_5_22
into 8eae91a on master.

@StevenACoffman StevenACoffman removed the help wanted Extra attention is needed label Jan 27, 2025
@StevenACoffman StevenACoffman merged commit 6cb6e32 into master Jan 27, 2025
@StevenACoffman StevenACoffman deleted the update_gqlparser_v2_v2_5_22 branch January 27, 2025 22:26
@peter-svensson
Copy link
Copy Markdown

Nice! Any idea when this will be released?
I cannot update my go.mod dependencies for vektah/gqlparser/v2 to v2.5.22 until then, not a big issue but it's always nice to get the latest stuff in (and keep Dependabot/Renovate happy 😊)

@StevenACoffman
Copy link
Copy Markdown
Collaborator Author

@peter-svensson I released https://github.com/99designs/gqlgen/releases/tag/v0.17.64 a few minutes ago.

Sorry for the awkward period where upgrading gqlparser would break gqlgen. 😞

@peter-svensson
Copy link
Copy Markdown

@peter-svensson I released https://github.com/99designs/gqlgen/releases/tag/v0.17.64 a few minutes ago.

Sorry for the awkward period where upgrading gqlparser would break gqlgen. 😞

No worries what so ever! Thanks for the great work!

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 this pull request may close these issues.

3 participants