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

Add endpoint to download Transmodel GraphQL Schema #6330

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
Expand Up @@ -2,9 +2,11 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.SchemaPrinter;
import io.micrometer.core.instrument.Tag;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
Expand All @@ -31,6 +33,15 @@
@Produces(MediaType.APPLICATION_JSON)
public class TransmodelAPI {

// Note, the blank line at the end is intended
private static final String SCHEMA_DOC_HEADER =
"""
# THIS IS NOT INTENDED FOR PRODUCTION USE. We recommend using the GraphQL introspection instead.
# This is intended for the OTP Debug UI and can also be used by humans to get the schema with the
# OTP configured default-values injected.

""";

private static final Logger LOG = LoggerFactory.getLogger(TransmodelAPI.class);

private static GraphQLSchema schema;
Expand Down Expand Up @@ -138,6 +149,13 @@ public Response getGraphQL(String query, @Context HttpHeaders headers) {
);
}

@GET
@Path("schema.graphql")
public Response getGraphQLSchema() {
var text = SCHEMA_DOC_HEADER + new SchemaPrinter().print(schema);
return Response.ok().encoding("UTF-8").entity(text).build();
}

private static Iterable<Tag> getTagsFromHeaders(HttpHeaders headers) {
return tracingHeaderTags
.stream()
Expand Down
Loading