safe GraphQL client for non-CLI calling scenarios#224
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the GraphQL client to safely handle missing context parameters in non-CLI scenarios by adding type checks and default values.
- Use safe context.Value extraction for
Insecure,BaseURL,Username,Password, andAuthorization - Provide a hard-coded default
baseURLwhen none is supplied - Construct Basic auth header only when both username and password are present
Comments suppressed due to low confidence (1)
pkg/graphql/client/client.go:58
- Add unit tests for scenarios where context values are missing to verify default baseURL, insecure flag handling, and authorization header construction.
if baseURL == "" {
kezhenxu94
reviewed
Jun 3, 2025
Member
kezhenxu94
left a comment
There was a problem hiding this comment.
Actually this GraphQL client is not coupled with CLI, if you are using this client in your MCP server, you should pass the context.Context with the contextkey.Insecure{} set to false
Member
|
Example: ctx := context.Background()
ctx = context.WithValue(ctx, contextkey.Insecure{}, true)
// pass the ctx to the graphql client |
Contributor
Author
|
@kezhenxu94 Yeah, I could default Insecure to true/false or make it configurable, I'll revert changes for this parameter. But for the other four parameters validation, let's keep this PR's approach, does this make sense to us? |
kezhenxu94
approved these changes
Jun 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To avoid panic when the caller comes from a non-cli scenario, parameters such as username may not have value, this pr adds relevant checks and default value.