Skip to content

Commit b371297

Browse files
committed
throw better exception for null id
1 parent 23ebecf commit b371297

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;NU5104;CS1573</NoWarn>
5-
<Version>21.3.0</Version>
5+
<Version>21.3.1</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
88
<ImplicitUsings>true</ImplicitUsings>

src/GraphQL.EntityFramework/Where/ArgumentReader.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ string ArgumentToExpression(object argument)
2323
};
2424
}
2525

26-
if (context.Arguments == null)
26+
var arguments = context.Arguments;
27+
if (arguments == null)
2728
{
2829
result = null;
2930
return false;
3031
}
3132

32-
var containsIds = context.Arguments.TryGetValue("ids", out var ids);
33-
var containsId = context.Arguments.TryGetValue("id", out var id);
33+
var containsIds = arguments.TryGetValue("ids", out var ids);
34+
var containsId = arguments.TryGetValue("id", out var id);
3435

3536
if (!containsIds && !containsId)
3637
{
3738
result = null;
3839
return false;
3940
}
4041

41-
if (ids.Source == ArgumentSource.FieldDefault && id.Source == ArgumentSource.FieldDefault)
42+
if (ids.Source == ArgumentSource.FieldDefault &&
43+
id.Source == ArgumentSource.FieldDefault)
4244
{
4345
result = null;
4446
return false;
@@ -48,7 +50,13 @@ string ArgumentToExpression(object argument)
4850

4951
if (id.Source != ArgumentSource.FieldDefault)
5052
{
51-
expressions.Add(ArgumentToExpression(id.Value!));
53+
var idValue = id.Value;
54+
if (idValue == null)
55+
{
56+
throw new("Null 'id' is not supported.");
57+
}
58+
59+
expressions.Add(ArgumentToExpression(idValue));
5260
}
5361

5462
if (ids.Source != ArgumentSource.FieldDefault)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
target: Error trying to resolve field 'parentEntity'.,
2+
target: {
3+
Type: Exception,
4+
Message: Null 'id' is not supported.
5+
},
36
sql: []
47
}

src/Tests/IntegrationTests/IntegrationTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,13 @@ static async Task RunQuery(
19431943
}
19441944
catch (ExecutionError executionError)
19451945
{
1946-
await Verify(executionError.Message, sourceFile: sourceFile);
1946+
await Verify(executionError.Message, sourceFile: sourceFile)
1947+
.IgnoreStackTrace();
1948+
}
1949+
catch (Exception exception)
1950+
{
1951+
await Verify(exception, sourceFile: sourceFile)
1952+
.IgnoreStackTrace();
19471953
}
19481954
}
19491955

src/Tests/IntegrationTests/QueryExecutor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static async Task<string> ExecuteQuery<TDbContext>(
2626
{
2727
Schema = schema,
2828
Query = query,
29+
ThrowOnUnhandledException = true,
2930
UserContext = new UserContextSingleDb<TDbContext>(data),
3031
Variables = inputs,
3132
};

0 commit comments

Comments
 (0)