'Graphql-Mutation : Schema Exception
I am trying to implement GraphQL -mutation using HotChocolate. But there is some issue with the schema (https://localhost:1234/graphql?sdl) and I am getting the unhandled exception:
The schema builder was unable to identify the query type of the schema. Either specify which type is the query type or set the schema builder to non-strict validation mode.
SchemaException: For more details look at the
Errorsproperty. 1. The schema builder was unable to identify the query type of the schema. Either specify which type is the query type or set the schema builder to non-strict validation mode.
My mutation code:
using HotChocolate
public class Book
{
public int Id { get; set; }
[GraphQLNonNullType]
public string Title { get; set; }
public int Pages { get; set; }
public int Chapters { get; set; }
}
public class Mutation
{
public async Task<Book> Book(string title, int pages, string author, int chapters)
{
var book = new Book
{
Title = title,
Chapters = chapters,
Pages = pages,
};
return book;
}
}
I have added the following in the API startup.cs file
public void ConfigureServices(IServiceCollection services)
{
services.AddGraphQLServer().AddMutationType<Mutation>();
}
Solution 1:[1]
You can try this:
public void ConfigureServices(IServiceCollection services)
{
services.AddGraphQLServer()
.ConfigureSchema(sb => sb.ModifyOptions(opts => opts.StrictValidation = false))
.AddMutationType<Mutation>();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thuan Thanh Tran |
