cosmo
cosmo copied to clipboard
fix: remove schema directives before in memory validation
Motivation and Context
This pull request introduces a new utility function to remove directive definitions and usages from a GraphQL schema and updates the relevant tests and commands to use this function.
New utility function:
cli/src/commands/mcp/tools/utils/schema.ts: AddedbuildSchemaWithoutDirectivesfunction to remove all directive definitions and usages from a GraphQL schema string and return a builtGraphQLSchema.
Tests for the new utility function:
cli/src/commands/mcp/tools/utils/__tests__/schema.test.ts: Added tests for thebuildSchemaWithoutDirectivesfunction to ensure it correctly removes directives from a schema.
Command updates:
cli/src/commands/mcp/tools/verify-query-against-in-memory-schema.ts: Updated the command to use the newbuildSchemaWithoutDirectivesfunction instead ofbuildSchema. [1] [2]- Renamed
schematoschemaStringto avoid conflict within theregisterVerifyQueryAgainstInMemorySchemaToolfunction.
@jensneuse I pushed my recommendations. I think we should use safeParse for the parsing of the sdl string otherwise it can throw. I don't know how or if you want to deal with the error, so I haven't changed that part and leave it up to you.