graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Subscription: Cannot execute request if no query is specified

Open ZedZipDev opened this issue 4 years ago • 1 comments
trafficstars

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.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) 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?

ZedZipDev avatar Jun 23 '21 12:06 ZedZipDev

For some reason, the server did not receive the text of the query - query property in incoming JSON. Check server logs for incoming requests.

sungam3r avatar Dec 14 '21 22:12 sungam3r