Add verbose logging support to GraphQL tools and validators#1
Add verbose logging support to GraphQL tools and validators#1
Conversation
📝 WalkthroughWalkthroughThe PR extends GraphQL tools with an optional verbose flag that propagates from agent configuration through the tool creation layer, enabling conditional structured debug output in validation and execution responses based on verbosity levels. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/tools/graphql-validate-excute.tool.ts`:
- Around line 39-51: The comment is wrong because formatResponse treats the
string '0' as truthy; update formatResponse to explicitly treat verbose === '0'
as non-verbose so verbose='0' returns plain text. Change the condition that
currently reads if (!verbose) to explicitly check for undefined/null or the
string '0' (e.g., if (verbose === undefined || verbose === null || verbose ===
'0')) so formatResponse(baseResult, debugInfo) returns baseResult for those
cases and only builds the ToolResponse JSON when verbose indicates structured
output.
🧹 Nitpick comments (2)
src/tools/graphql-schema-info.tool.ts (1)
9-9: Unusedverboseparameter.The
verboseparameter is added to the function signature but is never used within the function body. This appears to be dead code or an incomplete implementation. If verbose logging is intended for this tool as well, it should be implemented; otherwise, remove the parameter to avoid confusion.Option 1: Remove unused parameter
-export function createGraphQLSchemaInfoTool(config: GraphQLProjectConfig, logger?: Logger, verbose?: string): DynamicStructuredTool { +export function createGraphQLSchemaInfoTool(config: GraphQLProjectConfig, logger?: Logger): DynamicStructuredTool {This would also require updating the call site in
src/tools/index.ts.src/tools/graphql-validate-excute.tool.ts (1)
128-139: Inconsistent verbose handling for error paths.These error handling paths (Lines 128, 138) call
formatResponsewithout debug info, while similar error paths (e.g., Lines 83-89 for execution errors, Lines 277-283 for syntax errors) do include debug info whenverbose === '2'. For consistency, consider adding debug info to all error paths.Example for line 138
- return formatResponse(`Error executing query: ${(error as any).message}`); + const baseResult = `Error executing query: ${(error as any).message}`; + const debugInfo = verbose === '2' ? { + graphql_query: query, + execution_errors: [(error as any).message], + execution_time_ms: executionTime, + } : undefined; + return formatResponse(baseResult, debugInfo);
| // Helper function to format response based on verbose level | ||
| const formatResponse = (baseResult: string, debugInfo?: DebugInfo): string => { | ||
| // verbose = '0' or undefined: return plain text only | ||
| if (!verbose) { | ||
| return baseResult; | ||
| } | ||
| // verbose = '1' or '2': return structured JSON | ||
| const response: ToolResponse = { result: baseResult }; | ||
| if (debugInfo) { | ||
| response._debug = debugInfo; | ||
| } | ||
| return JSON.stringify(response); | ||
| }; |
There was a problem hiding this comment.
Comment contradicts code behavior for verbose='0'.
The comment on Line 41 states verbose = '0' or undefined: return plain text only, but the condition !verbose only handles undefined (and other falsy values). The string '0' is truthy in JavaScript, so !'0' evaluates to false, causing verbose='0' to fall through to the JSON branch unintentionally.
If the intent is for '0' to mean "no verbose output", the condition should explicitly check for it:
Proposed fix
// Helper function to format response based on verbose level
const formatResponse = (baseResult: string, debugInfo?: DebugInfo): string => {
// verbose = '0' or undefined: return plain text only
- if (!verbose) {
+ if (!verbose || verbose === '0') {
return baseResult;
}
// verbose = '1' or '2': return structured JSON🤖 Prompt for AI Agents
In `@src/tools/graphql-validate-excute.tool.ts` around lines 39 - 51, The comment
is wrong because formatResponse treats the string '0' as truthy; update
formatResponse to explicitly treat verbose === '0' as non-verbose so verbose='0'
returns plain text. Change the condition that currently reads if (!verbose) to
explicitly check for undefined/null or the string '0' (e.g., if (verbose ===
undefined || verbose === null || verbose === '0')) so formatResponse(baseResult,
debugInfo) returns baseResult for those cases and only builds the ToolResponse
JSON when verbose indicates structured output.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.