@@ -6,7 +6,7 @@ partial class EfGraphQLService<TDbContext>
6
6
public FieldBuilder < object , TReturn > AddFirstField < TReturn > (
7
7
IObjectGraphType graph ,
8
8
string name ,
9
- Func < ResolveEfFieldContext < TDbContext , object > , IQueryable < TReturn > > resolve ,
9
+ Func < ResolveEfFieldContext < TDbContext , object > , IQueryable < TReturn > ? > resolve ,
10
10
Func < ResolveEfFieldContext < TDbContext , object > , TReturn , Task > ? mutate = null ,
11
11
Type ? graphType = null ,
12
12
bool nullable = false ,
@@ -22,7 +22,7 @@ public FieldBuilder<object, TReturn> AddFirstField<TReturn>(
22
22
public FieldBuilder < object , TReturn > AddFirstField < TReturn > (
23
23
IObjectGraphType graph ,
24
24
string name ,
25
- Func < ResolveEfFieldContext < TDbContext , object > , Task < IQueryable < TReturn > > > resolve ,
25
+ Func < ResolveEfFieldContext < TDbContext , object > , Task < IQueryable < TReturn > ? > ? > resolve ,
26
26
Func < ResolveEfFieldContext < TDbContext , object > , TReturn , Task > ? mutate = null ,
27
27
Type ? graphType = null ,
28
28
bool nullable = false ,
@@ -38,7 +38,7 @@ public FieldBuilder<object, TReturn> AddFirstField<TReturn>(
38
38
public FieldBuilder < object , TReturn > AddFirstField < TReturn > (
39
39
IComplexGraphType graph ,
40
40
string name ,
41
- Func < ResolveEfFieldContext < TDbContext , object > , IQueryable < TReturn > > resolve ,
41
+ Func < ResolveEfFieldContext < TDbContext , object > , IQueryable < TReturn > ? > resolve ,
42
42
Func < ResolveEfFieldContext < TDbContext , object > , TReturn , Task > ? mutate = null ,
43
43
Type ? graphType = null ,
44
44
bool nullable = false ,
@@ -54,7 +54,7 @@ public FieldBuilder<object, TReturn> AddFirstField<TReturn>(
54
54
public FieldBuilder < object , TReturn > AddFirstField < TReturn > (
55
55
IComplexGraphType graph ,
56
56
string name ,
57
- Func < ResolveEfFieldContext < TDbContext , object > , Task < IQueryable < TReturn > > > resolve ,
57
+ Func < ResolveEfFieldContext < TDbContext , object > , Task < IQueryable < TReturn > ? > ? > resolve ,
58
58
Func < ResolveEfFieldContext < TDbContext , object > , TReturn , Task > ? mutate = null ,
59
59
Type ? graphType = null ,
60
60
bool nullable = false ,
@@ -70,7 +70,7 @@ public FieldBuilder<object, TReturn> AddFirstField<TReturn>(
70
70
public FieldBuilder < TSource , TReturn > AddFirstField < TSource , TReturn > (
71
71
IComplexGraphType graph ,
72
72
string name ,
73
- Func < ResolveEfFieldContext < TDbContext , TSource > , IQueryable < TReturn > > resolve ,
73
+ Func < ResolveEfFieldContext < TDbContext , TSource > , IQueryable < TReturn > ? > resolve ,
74
74
Func < ResolveEfFieldContext < TDbContext , TSource > , TReturn , Task > ? mutate = null ,
75
75
Type ? graphType = null ,
76
76
bool nullable = false ,
@@ -86,7 +86,7 @@ public FieldBuilder<TSource, TReturn> AddFirstField<TSource, TReturn>(
86
86
public FieldBuilder < TSource , TReturn > AddFirstField < TSource , TReturn > (
87
87
IComplexGraphType graph ,
88
88
string name ,
89
- Func < ResolveEfFieldContext < TDbContext , TSource > , Task < IQueryable < TReturn > > > resolve ,
89
+ Func < ResolveEfFieldContext < TDbContext , TSource > , Task < IQueryable < TReturn > ? > ? > resolve ,
90
90
Func < ResolveEfFieldContext < TDbContext , TSource > , TReturn , Task > ? mutate = null ,
91
91
Type ? graphType = null ,
92
92
bool nullable = false ,
@@ -101,7 +101,7 @@ public FieldBuilder<TSource, TReturn> AddFirstField<TSource, TReturn>(
101
101
102
102
FieldType BuildFirstField < TSource , TReturn > (
103
103
string name ,
104
- Func < ResolveEfFieldContext < TDbContext , TSource > , IQueryable < TReturn > > resolve ,
104
+ Func < ResolveEfFieldContext < TDbContext , TSource > , IQueryable < TReturn > ? > resolve ,
105
105
Func < ResolveEfFieldContext < TDbContext , TSource > , TReturn , Task > ? mutate ,
106
106
Type ? graphType ,
107
107
bool nullable ,
@@ -123,7 +123,7 @@ FieldType BuildFirstField<TSource, TReturn>(
123
123
124
124
FieldType BuildFirstField < TSource , TReturn > (
125
125
string name ,
126
- Func < ResolveEfFieldContext < TDbContext , TSource > , Task < IQueryable < TReturn > > > resolve ,
126
+ Func < ResolveEfFieldContext < TDbContext , TSource > , Task < IQueryable < TReturn > ? > ? > resolve ,
127
127
Func < ResolveEfFieldContext < TDbContext , TSource > , TReturn , Task > ? mutate ,
128
128
Type ? graphType ,
129
129
bool nullable ,
@@ -143,9 +143,20 @@ FieldType BuildFirstField<TSource, TReturn>(
143
143
Type = graphType ,
144
144
Resolver = new FuncFieldResolver < TSource , TReturn ? > ( async context =>
145
145
{
146
- var efFieldContext = BuildContext ( context ) ;
146
+ var fieldContext = BuildContext ( context ) ;
147
+
148
+ var task = resolve ( fieldContext ) ;
149
+ if ( task == null )
150
+ {
151
+ return ReturnNullable ( ) ;
152
+ }
153
+
154
+ var query = await task ;
155
+ if ( query == null )
156
+ {
157
+ return ReturnNullable ( ) ;
158
+ }
147
159
148
- var query = await resolve ( efFieldContext ) ;
149
160
if ( disableTracking )
150
161
{
151
162
query = query . AsNoTracking ( ) ;
@@ -187,24 +198,19 @@ FieldType BuildFirstField<TSource, TReturn>(
187
198
188
199
if ( first is not null )
189
200
{
190
- if ( efFieldContext . Filters == null ||
191
- await efFieldContext . Filters . ShouldInclude ( context . UserContext , efFieldContext . DbContext , context . User , first ) )
201
+ if ( fieldContext . Filters == null ||
202
+ await fieldContext . Filters . ShouldInclude ( context . UserContext , fieldContext . DbContext , context . User , first ) )
192
203
{
193
204
if ( mutate is not null )
194
205
{
195
- await mutate . Invoke ( efFieldContext , first ) ;
206
+ await mutate . Invoke ( fieldContext , first ) ;
196
207
}
197
208
198
209
return first ;
199
210
}
200
211
}
201
212
202
- if ( nullable )
203
- {
204
- return null ;
205
- }
206
-
207
- throw new FirstEntityNotFoundException ( ) ;
213
+ return ReturnNullable ( ) ;
208
214
} )
209
215
} ;
210
216
@@ -214,5 +220,8 @@ await efFieldContext.Filters.ShouldInclude(context.UserContext, efFieldContext.D
214
220
}
215
221
216
222
return type ;
223
+
224
+ TReturn ? ReturnNullable ( ) =>
225
+ nullable ? null : throw new FirstEntityNotFoundException ( ) ;
217
226
}
218
227
}
0 commit comments