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

feat: Expose GQL Extensions to OperationContext #3574

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

NavidMitchell
Copy link
Contributor

Describe your PR and link to any relevant issues.

#3573

I have:
Added the GQL Extensions to the OperationContext

@StevenACoffman
Copy link
Collaborator

Thanks for this contribution. I can see this being useful (although unit tests would be appreciated in the future). Can you say more about which specific GraphQL extensions you are hoping to expose to the operation context? Right now, by getting them from the RawParams you don't have a lot of type safety and there might be a better way to get the extension you want.

@StevenACoffman StevenACoffman merged commit 225b2eb into 99designs:master Mar 6, 2025
24 checks passed
@NavidMitchell
Copy link
Contributor Author

Hello @StevenACoffman thank you for the super fast response. :)

I will add tests in the future. Sorry about that.

In our case we are looking to pull a list of strings out of a specific extension key. I added the code as I did since GQL extensions are not strictly defined. https://graphql.org/learn/serving-over-http/#body .

As for type safety I generally prefer to have it as well. I hadn't thought about it in this case.

I guess we could add something like below somewhere? I'm somewhat of an experienced golang programmer so I am not sure if this adequate or not as well.

func GetExtensionValue[T any](c *OperationContext, key string) (T, error) {
	val, ok := c.Extensions[key]
	if !ok {
		var zero T
		return zero, errors.New("key not found")
	}
	tVal, ok := val.(T)
	if !ok {
		var zero T
		return zero, errors.New("type mismatch")
	}
	return tVal, nil
}

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.

None yet

2 participants