I have my repo at https://github.com/nmarun/customergraph. When I run the application, I don't see any schema in the document explorer. I see a 404 when I look at the Network tab.
I think I need to configure GraphiQl to call the /graphql endpoint to retrieve schema details and for some reason my HTTP POST action method is not getting hit at /graph endpoint.
All calls through postman are working fine when I hit the endpoint though: http://localhost:54068/graphql
Please assist.
using CustomerGraph.Models.Schema;
using CustomerGraph.Models.Services;
using GraphiQl;
using GraphQL;
using GraphQL.Server;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace CustomerGraph
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddScoped<IDocumentExecuter, DocumentExecuter>();
services.AddSingleton<ICustomerService, CustomerService>();
services.AddSingleton<CustomerType>();
services.AddSingleton<AddressType>();
services.AddSingleton<ContactType>();
services.AddSingleton<ContactMethodType>();
services.AddSingleton<CustomersQuery>();
services.AddSingleton<CustomerSchema>();
services.AddSingleton<IDependencyResolver>(
c => new FuncDependencyResolver(type => c.GetRequiredService(type)));
services.AddGraphQL(_ =>
{
_.EnableMetrics = true;
_.ExposeExceptions = true;
});
var sp = services.BuildServiceProvider();
services.AddSingleton<ISchema>(new CustomerSchema(new FuncDependencyResolver(type => sp.GetService(type))));
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseGraphiQl("/graphiql");
app.UseGraphQL<ISchema>("/graphql");
app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();
}
}
}
Thanks, Arun
This is caused by the UseGraphIQL method, it assumes that the graphql endpoint is at the same place as the GraphQL api.
Fix it by replacing the following:
app.UseGraphiQl("/graphiql");
//app.UseGraphQL<CustomerSchema>("/graph");
//app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
//app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();
by:
app.UseGraphiQl("/graphiql", "/graphql");
app.UseGraphQL<CustomerSchema>("/graphql");
app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();