You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I did upgrade from version 5 to v7 and need to fix query injection issue.
Sharing code from V5
public class MainSchema : Schema
{
public MainSchema(IServiceProvider provider) : base(provider)
{
Query = provider.GetRequiredService<RootQuery>();
Mutation = provider.GetRequiredService<RootMutation>();
}
}
public class RootQuery : ObjectGraphType
{
public RootQuery(GameDirectoryQuery gameDirectoryQuery, GameFeaturesQuery gameFeaturesQuery)
{
AddField(gameDirectoryQuery.GetGames());
AddField(gameDirectoryQuery.GetGameLogs());
AddField(gameFeaturesQuery.GetGameFeatures());
}
}
where GameDirectoryQuery and GameFeaturesQuery extends ObjectGraphType class.
I updated FieldType methods for each query class and when I try to attach each of them in MainSchema like:
Query = provider.GetRequiredService();
both of them works.
But getting error when I inject RootQuery with whose query classes and trying to add fields through RootQuery constructor, like this:
public class RootQuery : ObjectGraphType
{
public RootQuery(GameDirectoryQuery gameDirectoryQuery, GameFeaturesQuery gameFeaturesQuery)
{
gameDirectoryQuery.GetGames();
gameDirectoryQuery.GetGameLogs();
gameFeaturesQuery.GetGameFeatures();
}
}
Error Description:
"details": "GraphQL.Execution.UnhandledError: Error executing document.\r\n ---> System.InvalidOperationException: An Object type 'RootQuery' must define one or more fields.\r\n at GraphQL.Utilities.SchemaValidationVisitor.VisitObject(IObjectGraphType type, ISchema schema) in /_/src/GraphQL/Utilities/Visitors/SchemaValidationVisitor.cs:line 32\r\n at GraphQL.SchemaExtensions.Run(ISchemaNodeVisitor visitor, ISchema schema) in /_/src/GraphQL/Extensions/SchemaExtensions.cs:line 325\r\n at GraphQL.Types.Schema.Validate() in /_/src/GraphQL/Types/Schema.cs:line 489\r\n at GraphQL.Types.Schema.CreateAndInitializeSchemaTypes() in /_/src/GraphQL/Types/Schema.cs:line 459\r\n at GraphQL.Types.Schema.Initialize() in /_/src/GraphQL/Types/Schema.cs:line 196\r\n at GraphQL.DocumentExecuter.CoreExecuteAsync(ExecutionOptions options) in /_/src/GraphQL/Execution/DocumentExecuter.cs:line 101\r\n --- End of inner exception stack trace ---"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I did upgrade from version 5 to v7 and need to fix query injection issue.
Sharing code from V5
where GameDirectoryQuery and GameFeaturesQuery extends ObjectGraphType class.
I updated FieldType methods for each query class and when I try to attach each of them in MainSchema like:
Query = provider.GetRequiredService();
both of them works.
But getting error when I inject RootQuery with whose query classes and trying to add fields through RootQuery constructor, like this:
Beta Was this translation helpful? Give feedback.
All reactions