graphql-client
graphql-client copied to clipboard
Subscription: Cannot execute request if no query is specified
I have used the sample code as described here https://github.com/graphql-dotnet/graphql-client
My code is:
public static async void MRTestSub()
{
var graphQLClient = new GraphQLHttpClient(serviceURL, new NewtonsoftJsonSerializer());
var usdbActionAddedRequest = new GraphQLRequest
{
Query = @"
subscription {
dbActionAdded{
name
id
}
}"
};
try
{
IObservable<GraphQLResponse<DbActionAddedSubscriptionResult>> subscriptionStream
= graphQLClient.CreateSubscriptionStream<DbActionAddedSubscriptionResult>(usdbActionAddedRequest);
var subscription = subscriptionStream.Subscribe(response =>
{
Console.WriteLine($"DbAction '{response.Data.DbActionAdded.Name}' added");
});
Console.WriteLine("=Sub===============");
}
catch (Exception x)
{
Console.WriteLine("*** Exception: "+x.Message);
}
return;
}
but when the client tries to subscribe my asp.net core server gives an exception
info: Microsoft.Hosting.Lifetime[0] Now listening on: https://localhost:6061 info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:6060 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\GraphQL2\Movie_reviews-1\movie-reviews-main-1 fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Cannot execute request if no query is specified at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options) in //src/GraphQL/Execution/DocumentExecuter.cs:line 56 at GraphQL.Server.Internal.DefaultGraphQLExecuter
1.ExecuteAsync(String operationName, String query, Inputs variables, IDictionary2 context, IServiceProvider requestServices, CancellationToken cancellationToken) in //src/Core/Internal/DefaultGraphQLExecuter.cs:line 54 at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware1.InvokeAsync(HttpContext context) in /_/src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 144 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Cannot execute request if no query is specified at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options) in /_/src/GraphQL/Execution/DocumentExecuter.cs:line 56 at GraphQL.Server.Internal.DefaultGraphQLExecuter1.ExecuteAsync(String operationName, String query, Inputs variables, IDictionary2 context, IServiceProvider requestServices, CancellationToken cancellationToken) in /_/src/Core/Internal/DefaultGraphQLExecuter.cs:line 54 at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware1.InvokeAsync(HttpContext context) in //src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 144 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Cannot execute request if no query is specified at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options) in //src/GraphQL/Execution/DocumentExecuter.cs:line 56 at GraphQL.Server.Internal.DefaultGraphQLExecuter1.ExecuteAsync(String operationName, String query, Inputs variables, IDictionary2 context, IServiceProvider requestServices, CancellationToken cancellationToken) in //src/Core/Internal/DefaultGraphQLExecuter.cs:line 54 at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware1.InvokeAsync(HttpContext context) in /_/src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 144 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: Cannot execute request if no query is specified at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options) in /_/src/GraphQL/Execution/DocumentExecuter.cs:line 56 at GraphQL.Server.Internal.DefaultGraphQLExecuter1.ExecuteAsync(String operationName, String query, Inputs variables, IDictionary2 context, IServiceProvider requestServices, CancellationToken cancellationToken) in /_/src/Core/Internal/DefaultGraphQLExecuter.cs:line 54 at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware1.InvokeAsync(HttpContext context) in //src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 144 at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
What is wrong? How to fix it?
For some reason, the server did not receive the text of the query - query property in incoming JSON. Check server logs for incoming requests.