Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ public static FieldDefinitionNode GenerateStoredProcedureSchema(
fieldDefinitionNodeDirectives.Add(authorizeDirective!);
}

string description = !string.IsNullOrWhiteSpace(entity.Description)
? entity.Description
: $"Execute Stored-Procedure {name.Value} and get results from the database";

return new(
location: null,
new NameNode(GenerateStoredProcedureGraphQLFieldName(name.Value, entity)),
new StringValueNode($"Execute Stored-Procedure {name.Value} and get results from the database"),
new StringValueNode(description),
inputValues,
new NonNullTypeNode(new ListTypeNode(new NonNullTypeNode(new NamedTypeNode(name)))),
fieldDefinitionNodeDirectives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,48 @@ public void StoredProcedure_RequiredWithDefault_KeepsDefaultValue()
Assert.AreEqual("Demo Title", ((StringValueNode)arg.DefaultValue!).Value);
}

[TestMethod]
public void StoredProcedure_Description_UsesEntityDescription()
{
const string entityDescription = "Entity description from config";

DatabaseObject spDbObj = new DatabaseStoredProcedure(schemaName: "dbo", tableName: "spDescriptionTest")
{
SourceType = EntitySourceType.StoredProcedure,
StoredProcedureDefinition = new()
};

FieldDefinitionNode field = BuildSchemaAndGetExecuteField(
spDbObj: spDbObj,
configParameters: new List<ParameterMetadata>(),
graphQLTypeName: "SpDescriptionType",
entityName: "SpDescription",
entityDescription: entityDescription);

Assert.AreEqual(entityDescription, field.Description?.Value);
Comment thread
anushakolan marked this conversation as resolved.
}

[TestMethod]
public void StoredProcedure_Description_UsesDefaultWhenEntityDescriptionIsNull()
{
DatabaseObject spDbObj = new DatabaseStoredProcedure(schemaName: "dbo", tableName: "spDescriptionTest")
{
SourceType = EntitySourceType.StoredProcedure,
StoredProcedureDefinition = new()
};

FieldDefinitionNode field = BuildSchemaAndGetExecuteField(
spDbObj: spDbObj,
configParameters: new List<ParameterMetadata>(),
graphQLTypeName: "SpDescriptionType",
entityName: "SpDescription",
entityDescription: null);

// When entityDescription is null, verify the field uses the default generated description
string expectedDescription = "Execute Stored-Procedure SpDescriptionType and get results from the database";
Assert.AreEqual(expectedDescription, field.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
Expand All @@ -364,12 +406,14 @@ private static FieldDefinitionNode BuildSchemaAndGetExecuteField(
DatabaseObject spDbObj,
List<ParameterMetadata> configParameters,
string graphQLTypeName,
string entityName)
string entityName,
string? entityDescription = null)
{
Entity spEntity = GraphQLTestHelpers.GenerateStoredProcedureEntity(
graphQLTypeName: graphQLTypeName,
graphQLOperation: GraphQLOperation.Query,
parameters: configParameters);
parameters: configParameters) with
{ Description = entityDescription };

ObjectTypeDefinitionNode objectType = CreateGraphQLTypeForEntity(spEntity, entityName, spDbObj);

Expand Down