Skip to content

Fixes the bug #1680 that necessitated adding the 'name' parameter to the @model directive, regardless of the name of the GraphQL object type's name. #1714

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

Merged
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
10 changes: 7 additions & 3 deletions src/Service.GraphQLBuilder/GraphQLUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ public static bool TryExtractGraphQLFieldModelName(IDirectiveCollection fieldDir
{
if (dir.Name.Value == ModelDirectiveType.DirectiveName)
{
dir.ToObject<ModelDirectiveType>();
modelName = dir.GetArgument<string>(ModelDirectiveType.ModelNameArgument).ToString();
ModelDirectiveType modelDirectiveType = dir.ToObject<ModelDirectiveType>();

if (modelDirectiveType.Name.HasValue)
{
modelName = dir.GetArgument<string>(ModelDirectiveType.ModelNameArgument).ToString();
return modelName is not null;
}

return modelName is not null;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Service.Tests/CosmosTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Azure.DataApiBuilder.Service.Tests.CosmosTests;
public class TestBase
{
internal const string DATABASE_NAME = "graphqldb";
// Intentionally removed name attibute from Planet model to test scenario where the 'name' attribute
// is not explicitly added in the schema
internal const string GRAPHQL_SCHEMA = @"
type Character @model(name:""Character"") {
id : ID,
Expand All @@ -39,7 +41,7 @@ type Character @model(name:""Character"") {
star: Star
}

type Planet @model(name:""Planet"") {
type Planet @model {
id : ID!,
name : String,
character: Character,
Expand Down