Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL Schema #6639

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net;
using System.Threading.Tasks;
using GraphQL.Utilities;
using Microsoft.AspNetCore.Http;

namespace OrchardCore.Apis.GraphQL
{
public class SchemaMiddleware
{
private readonly RequestDelegate _next;

public SchemaMiddleware(RequestDelegate next)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could probably ditch this ctor as its not used

{
_next = next;
}

public async Task Invoke(HttpContext context, ISchemaFactory schemaService)
{
var schema = await schemaService.GetSchemaAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably check permissions .. dont wanna leak the schema just because graphql is turned on ...


using (var printer = new SchemaPrinter(schema))
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.OK;

await context.Response.WriteAsync(printer.Print());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you still need to invoke _next ?

}
}
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro
);

app.UseMiddleware<GraphQLMiddleware>(serviceProvider.GetService<IOptions<GraphQLSettings>>().Value);

app.Map("/api/schema.graphql", configuration => configuration.UseMiddleware<SchemaMiddleware>());
}
}
}