-
Notifications
You must be signed in to change notification settings - Fork 356
Use config parameter descriptions in GraphQL stored procedure args #3733
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
base: main
Are you sure you want to change the base?
Changes from all commits
558c2ed
cc39f40
4d1d10b
94c159a
c1f21b6
b5be078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -355,6 +355,104 @@ public void StoredProcedure_RequiredWithDefault_KeepsDefaultValue() | |
| Assert.AreEqual("Demo Title", ((StringValueNode)arg.DefaultValue!).Value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void StoredProcedure_ParameterDescription_UsesConfigDescription() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't exercise the production path that appears responsible for the underlying issue. During normal initialization, both SQL metadata-provider implementations copy Here the test bypasses that merge and manually creates a state where Could we add a regression test that starts from runtime config, initializes the metadata provider, builds the GraphQL schema, and asserts the argument description through introspection? Ideally, that test should fail on the PR's base commit. If it already passes on the base, we should identify and cover the specific path. |
||
| { | ||
| const string parameterName = "title"; | ||
| const string configDescription = "Title from runtime config"; | ||
| const string dbDescription = "Title from database metadata"; | ||
|
|
||
| DatabaseObject spDbObj = new DatabaseStoredProcedure(schemaName: "dbo", tableName: "spParamDesc") | ||
| { | ||
| SourceType = EntitySourceType.StoredProcedure, | ||
| StoredProcedureDefinition = new() | ||
| { | ||
| Parameters = new() | ||
| { | ||
| { parameterName, new() { SystemType = typeof(string), Description = dbDescription } } | ||
| } | ||
| } | ||
| }; | ||
| spDbObj.SourceDefinition.Columns.TryAdd("col1", new() { SystemType = typeof(string) }); | ||
|
|
||
| List<ParameterMetadata> configParameters = new() | ||
| { | ||
| new ParameterMetadata | ||
| { | ||
| Name = parameterName, | ||
| Description = configDescription | ||
| } | ||
| }; | ||
|
|
||
| FieldDefinitionNode field = BuildSchemaAndGetExecuteField( | ||
| spDbObj: spDbObj, | ||
| configParameters: configParameters, | ||
| graphQLTypeName: "SpParamDescType", | ||
| entityName: "SpParamDesc"); | ||
|
|
||
| InputValueDefinitionNode arg = field.Arguments.First(a => a.Name.Value == parameterName); | ||
| Assert.IsNotNull(arg.Description); | ||
| Assert.AreEqual(configDescription, arg.Description!.Value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void StoredProcedure_ParameterDescription_FallsBackToDatabaseDescription() | ||
| { | ||
| const string parameterName = "title"; | ||
| const string dbDescription = "Title from database metadata"; | ||
|
|
||
| DatabaseObject spDbObj = new DatabaseStoredProcedure(schemaName: "dbo", tableName: "spParamDescFallback") | ||
| { | ||
| SourceType = EntitySourceType.StoredProcedure, | ||
| StoredProcedureDefinition = new() | ||
| { | ||
| Parameters = new() | ||
| { | ||
| { parameterName, new() { SystemType = typeof(string), Description = dbDescription } } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we really get description of a parameter from database metadata? the definition here maybe showing the property Description, but are you sure it can get populated by querying the database? Did you test that? |
||
| } | ||
| } | ||
| }; | ||
| spDbObj.SourceDefinition.Columns.TryAdd("col1", new() { SystemType = typeof(string) }); | ||
|
|
||
| FieldDefinitionNode field = BuildSchemaAndGetExecuteField( | ||
| spDbObj: spDbObj, | ||
| configParameters: new List<ParameterMetadata>(), | ||
| graphQLTypeName: "SpParamDescFallbackType", | ||
| entityName: "SpParamDescFallback"); | ||
|
|
||
| InputValueDefinitionNode arg = field.Arguments.First(a => a.Name.Value == parameterName); | ||
| Assert.IsNotNull(arg.Description); | ||
| Assert.AreEqual(dbDescription, arg.Description!.Value); | ||
| } | ||
|
|
||
|
Copilot marked this conversation as resolved.
|
||
| [TestMethod] | ||
| public void StoredProcedure_ParameterDescription_FallsBackToDefaultText() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| { | ||
| const string parameterName = "title"; | ||
| const string graphQLTypeName = "SpParamDescDefaultTextType"; | ||
| const string entityName = "SpParamDescDefaultText"; | ||
|
|
||
| DatabaseObject spDbObj = new DatabaseStoredProcedure(schemaName: "dbo", tableName: "spParamDescDefaultText") | ||
| { | ||
| SourceType = EntitySourceType.StoredProcedure, | ||
| StoredProcedureDefinition = new() | ||
| { | ||
| Parameters = new() { { parameterName, new() { SystemType = typeof(string) } } } | ||
| } | ||
| }; | ||
| spDbObj.SourceDefinition.Columns.TryAdd("col1", new() { SystemType = typeof(string) }); | ||
|
|
||
| FieldDefinitionNode field = BuildSchemaAndGetExecuteField( | ||
| spDbObj: spDbObj, | ||
| configParameters: new List<ParameterMetadata>(), | ||
| graphQLTypeName: graphQLTypeName, | ||
| entityName: entityName); | ||
|
|
||
| InputValueDefinitionNode arg = field.Arguments.First(a => a.Name.Value == parameterName); | ||
| Assert.IsNotNull(arg.Description); | ||
| Assert.AreEqual($"parameters for {graphQLTypeName} stored-procedure", arg.Description!.Value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper that builds a query schema for a stored-procedure entity and returns | ||
| /// the generated execute* field so individual tests can assert on its argument | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This direct config lookup creates first-wins behavior for descriptions because
FirstOrDefault()selects the first matching parameter. Metadata hydration has different behavior: it iterates the complete parameter list and repeatedly assigns to the sameParameterDefinition, so the last duplicate wins.The parameter-array schema currently does not enforce uniqueness by
name. For a config containing twotitleentries with different descriptions, GraphQL would now expose the first description while OpenAPI/MCP can expose the last merged description.Could we either reject duplicate parameter names during semantic config validation or use the normalized
ParameterDefinitionconsistently here? Rejecting duplicates would be preferable because it also removes ambiguity forrequiredanddefault.