Skip to content

Commit 82e5f75

Browse files
committed
SafeToQueryString
1 parent 3ed4b74 commit 82e5f75

9 files changed

Lines changed: 52 additions & 12 deletions

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.3.0</Version>
5+
<Version>32.3.1</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<PackageTags>EntityFrameworkCore, EntityFramework, GraphQL</PackageTags>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
static class EfExtensions
2+
{
3+
public static string SafeToQueryString(this IQueryable query)
4+
{
5+
try
6+
{
7+
return query.ToQueryString();
8+
}
9+
catch (Exception exception)
10+
{
11+
return "Could not resolve ToQueryString: " + exception.Message;
12+
}
13+
}
14+
}

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_First.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ FieldType BuildFirstField<TSource, TReturn>(
198198
OmitQueryArguments: {omitQueryArguments}
199199
Nullable: {nullable}
200200
KeyNames: {JoinKeys(names)}
201-
Query: {query.ToQueryString()}
201+
Query: {query.SafeToQueryString()}
202202
""",
203203
exception);
204204
}
@@ -229,6 +229,6 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
229229
return type;
230230

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

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Queryable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ FieldType BuildQueryField<TSource, TReturn>(
149149
DisableTracking: {disableTracking}
150150
HasId: {hasId}
151151
KeyNames: {JoinKeys(names)}
152-
Query: {query.ToQueryString()}
152+
Query: {query.SafeToQueryString()}
153153
""",
154154
exception);
155155
}

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_QueryableConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ConnectionBuilder<TSource> AddQueryableConnection<TSource, TGraph, TReturn>(
186186
TSource: {typeof(TSource).FullName}
187187
TReturn: {typeof(TReturn).FullName}
188188
KeyNames: {JoinKeys(names)}
189-
Query: {query.ToQueryString()}
189+
Query: {query.SafeToQueryString()}
190190
""",
191191
exception);
192192
}

src/GraphQL.EntityFramework/GraphApi/EfGraphQLService_Single.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ FieldType BuildSingleField<TSource, TReturn>(
199199
OmitQueryArguments: {omitQueryArguments}
200200
Nullable: {nullable}
201201
KeyNames: {JoinKeys(names)}
202-
Query: {query.ToQueryString()}
202+
Query: {query.SafeToQueryString()}
203203
""",
204204
exception);
205205
}
@@ -230,6 +230,6 @@ await fieldContext.Filters.ShouldInclude(context.UserContext, fieldContext.DbCon
230230
return type;
231231

232232
TReturn? ReturnNullable(IQueryable<TReturn>? query = null) =>
233-
nullable ? null : throw new SingleEntityNotFoundException(query?.ToQueryString());
233+
nullable ? null : throw new SingleEntityNotFoundException(query?.SafeToQueryString());
234234
}
235235
}

src/GraphQL.EntityFramework/QueryLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public static void Enable(Action<string> log) =>
88
QueryLogger.log = log;
99

1010
internal static void Write(IQueryable queryable) =>
11-
log?.Invoke(queryable.ToQueryString());
11+
log?.Invoke(queryable.SafeToQueryString());
1212
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2-
Type: InvalidOperationException,
3-
Message: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
2+
Type: Exception,
3+
Message:
4+
Failed to execute query for field `parentEntities`
5+
GraphType: GraphQL.Types.NonNullGraphType`1[[GraphQL.Types.ListGraphType`1[[GraphQL.Types.NonNullGraphType`1[[ParentGraphType, Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ef9e5a364f5893c5]], GraphQL, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e6238258560628ee]], GraphQL, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e6238258560628ee]]
6+
TSource: System.Object
7+
TReturn: ParentEntity
8+
DisableTracking: False
9+
HasId: True
10+
KeyNames: Id
11+
Query: Could not resolve ToQueryString: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.,
12+
InnerException: {
13+
$type: InvalidOperationException,
14+
Type: InvalidOperationException,
15+
Message: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
16+
}
417
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2-
Type: InvalidOperationException,
3-
Message: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
2+
Type: Exception,
3+
Message:
4+
Failed to execute query for field `parentEntities`
5+
GraphType: GraphQL.Types.NonNullGraphType`1[[GraphQL.Types.ListGraphType`1[[GraphQL.Types.NonNullGraphType`1[[ParentGraphType, Tests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ef9e5a364f5893c5]], GraphQL, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e6238258560628ee]], GraphQL, Version=8.5.0.0, Culture=neutral, PublicKeyToken=e6238258560628ee]]
6+
TSource: System.Object
7+
TReturn: ParentEntity
8+
DisableTracking: False
9+
HasId: True
10+
KeyNames: Id
11+
Query: Could not resolve ToQueryString: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.,
12+
InnerException: {
13+
$type: InvalidOperationException,
14+
Type: InvalidOperationException,
15+
Message: An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning': The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased. This exception can be suppressed or logged by passing event ID 'CoreEventId.RowLimitingOperationWithoutOrderByWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
16+
}
417
}

0 commit comments

Comments
 (0)