cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

fix: remove schema directives before in memory validation

Open jensneuse opened this issue 7 months ago • 1 comments

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: Added buildSchemaWithoutDirectives function to remove all directive definitions and usages from a GraphQL schema string and return a built GraphQLSchema.

Tests for the new utility function:

  • cli/src/commands/mcp/tools/utils/__tests__/schema.test.ts: Added tests for the buildSchemaWithoutDirectives function 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 new buildSchemaWithoutDirectives function instead of buildSchema. [1] [2]
  • Renamed schema to schemaString to avoid conflict within the registerVerifyQueryAgainstInMemorySchemaTool function.

jensneuse avatar Apr 14 '25 20:04 jensneuse

@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.

Aenimus avatar Apr 26 '25 14:04 Aenimus