I have a really simple setup but wondering how do I register multiple queries? For example, this is my code so far:
I guess my question is how do I access the GetAllMoviesQuery
. When I enter https://localhost:7058/admin/graphql/ or https://localhost:7058/graphql/ I can only see book query not movies.
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddGraphQLServer()
.AddQueryType<GetAllBooksQuery>();
builder.Services
.AddGraphQLServer("foo")
.AddQueryType<GetAllMoviesQuery>();
var app = builder.Build();
app.MapGraphQL();
app.MapGraphQL("/admin/graphql", schemaName: "foo");
app.MapGet("/health", () =>
{
return new OkResult();
});
app.Run();
public class Movie
{
public string Name { get; set; }
}
public class Book
{
public string Title { get; set; }
public Author Author { get; set; }
}
public class Author
{
public string Name { get; set; }
}
public class GetAllMoviesQuery
{
public Movie GetMovies()
{
return new Movie
{
Name = "Top Gun"
};
}
}
public class GetAllBooksQuery
{
public Book GetBookById(string id)
{
return new Book
{
Title = id
};
}
public Book GetBooks()
{
return new Book
{
Title = "Hello World",
Author = new Author {Name = "Foo Bar"}
};
}
}