Skip to content

Commit 6aece0a

Browse files
neeraj-sharma2592Neeraj Sharma
and
Neeraj Sharma
committed
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. (#1706)
## Why make this change? - Closes #1680 - Regression introduced in 0.8.49 caused required explicitly adding "name" directive for all the model/entity irrespective of whether we are using a different name than the one it originally has. - Regression introduced in #1402 when we started using TryExtractGraphQLName as follows: ``` string typeName = GraphQLUtils.TryExtractGraphQLFieldModelName(underlyingType.Directives, out string? modelName) ? modelName : underlyingType.Name; ``` ## What is this change? Checking Directive "name" exists before accessing its value. ## How was this tested? Tested locally for now. Will be checking Test cases for it. - [x] Integration Tests - [ ] Unit Tests --------- Co-authored-by: Neeraj Sharma <[email protected]>
1 parent d9f2a1a commit 6aece0a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Service.GraphQLBuilder/GraphQLUtils.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ public static bool TryExtractGraphQLFieldModelName(IDirectiveCollection fieldDir
186186
{
187187
if (dir.Name.Value == ModelDirectiveType.DirectiveName)
188188
{
189-
dir.ToObject<ModelDirectiveType>();
190-
modelName = dir.GetArgument<string>(ModelDirectiveType.ModelNameArgument).ToString();
189+
ModelDirectiveType modelDirectiveType = dir.ToObject<ModelDirectiveType>();
190+
191+
if (modelDirectiveType.Name.HasValue)
192+
{
193+
modelName = dir.GetArgument<string>(ModelDirectiveType.ModelNameArgument).ToString();
194+
return modelName is not null;
195+
}
191196

192-
return modelName is not null;
193197
}
194198
}
195199

src/Service.Tests/CosmosTests/TestBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace Azure.DataApiBuilder.Service.Tests.CosmosTests;
2929
public class TestBase
3030
{
3131
internal const string DATABASE_NAME = "graphqldb";
32+
// Intentionally removed name attibute from Planet model to test scenario where the 'name' attribute
33+
// is not explicitly added in the schema
3234
internal const string GRAPHQL_SCHEMA = @"
3335
type Character @model(name:""Character"") {
3436
id : ID,
@@ -39,7 +41,7 @@ type Character @model(name:""Character"") {
3941
star: Star
4042
}
4143
42-
type Planet @model(name:""Planet"") {
44+
type Planet @model {
4345
id : ID!,
4446
name : String,
4547
character: Character,

0 commit comments

Comments
 (0)