Skip to content

Commit a19e285

Browse files
committed
Add more Query to SingleEntityNotFoundException and FirstEntityNotFoundException
1 parent 727f14b commit a19e285

8 files changed

+80
-17
lines changed

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;CS9107;NU1608;NU1109</NoWarn>
5-
<Version>32.2.0</Version>
5+
<Version>32.3.0</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
217217
}
218218
}
219219

220-
return ReturnNullable();
220+
return ReturnNullable(query);
221221
})
222222
};
223223

@@ -228,7 +228,7 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
228228

229229
return type;
230230

231-
TReturn? ReturnNullable() =>
232-
nullable ? null : throw new FirstEntityNotFoundException();
231+
TReturn? ReturnNullable(IQueryable<TReturn>? query = null) =>
232+
nullable ? null : throw new FirstEntityNotFoundException(query?.ToQueryString());
233233
}
234234
}

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
218218
}
219219
}
220220

221-
return ReturnNullable();
221+
return ReturnNullable(query);
222222
})
223223
};
224224

@@ -229,7 +229,7 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
229229

230230
return type;
231231

232-
TReturn? ReturnNullable() =>
233-
nullable ? null : throw new SingleEntityNotFoundException();
232+
TReturn? ReturnNullable(IQueryable<TReturn>? query = null) =>
233+
nullable ? null : throw new SingleEntityNotFoundException(query?.ToQueryString());
234234
}
235235
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace GraphQL.EntityFramework;
2+
3+
public class FirstEntityNotFoundException(string? query = null) :
4+
Exception
5+
{
6+
public override string Message
7+
{
8+
get
9+
{
10+
if (Query == null)
11+
{
12+
return "Not found";
13+
}
14+
15+
return $"""
16+
Not found.
17+
Query:
18+
{Query}
19+
""";
20+
}
21+
}
22+
23+
public string? Query { get; } = query;
24+
}
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
namespace GraphQL.EntityFramework;
22

3-
public class SingleEntityNotFoundException :
3+
public class SingleEntityNotFoundException(string? query = null) :
44
Exception
55
{
6-
public override string Message => "Not found";
7-
}
8-
public class FirstEntityNotFoundException :
9-
Exception
10-
{
11-
public override string Message => "Not found";
6+
public override string Message
7+
{
8+
get
9+
{
10+
if (Query == null)
11+
{
12+
return "Not found";
13+
}
14+
15+
return $"""
16+
Not found.
17+
Query:
18+
{Query}
19+
""";
20+
}
21+
}
22+
23+
public string? Query { get; } = query;
1224
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
22
Type: SingleEntityNotFoundException,
3-
Message: Not found
3+
Message:
4+
Not found.
5+
Query:
6+
SELECT [c].[Id], [c].[Content]
7+
FROM [Companies] AS [c]
8+
WHERE [c].[Id] = 99,
9+
Query:
10+
SELECT [c].[Id], [c].[Content]
11+
FROM [Companies] AS [c]
12+
WHERE [c].[Id] = 99
413
}

src/Tests/IntegrationTests/IntegrationTests.First_NotFound.verified.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
22
target: {
33
Type: FirstEntityNotFoundException,
4-
Message: Not found
4+
Message:
5+
Not found.
6+
Query:
7+
SELECT [p].[Id], [p].[Property]
8+
FROM [ParentEntities] AS [p]
9+
WHERE [p].[Id] = '00000000-0000-0000-0000-000000000001',
10+
Query:
11+
SELECT [p].[Id], [p].[Property]
12+
FROM [ParentEntities] AS [p]
13+
WHERE [p].[Id] = '00000000-0000-0000-0000-000000000001'
514
},
615
sql: {
716
Text:

src/Tests/IntegrationTests/IntegrationTests.Single_NotFound.verified.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
22
target: {
33
Type: SingleEntityNotFoundException,
4-
Message: Not found
4+
Message:
5+
Not found.
6+
Query:
7+
SELECT [p].[Id], [p].[Property]
8+
FROM [ParentEntities] AS [p]
9+
WHERE [p].[Id] = '00000000-0000-0000-0000-000000000001',
10+
Query:
11+
SELECT [p].[Id], [p].[Property]
12+
FROM [ParentEntities] AS [p]
13+
WHERE [p].[Id] = '00000000-0000-0000-0000-000000000001'
514
},
615
sql: {
716
Text:

0 commit comments

Comments
 (0)