Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,27 @@ 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already a test that checks if the entityDescription is null it will use the hard coded 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 +385,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