use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.
the class KubernetesGatewayService method getGatewayWriteSchema.
@Override
public Single<SchemaData> getGatewayWriteSchema(final String name, final String type, final SchemaFormat format) {
final GatewaySchema gatewaySchema = new GatewaySchema(name, type);
// make sure the gateway exists
final Completable exists = this.kubernetesManagerClient.checkDeploymentExistence(ResourcePrefix.GATEWAY, name);
final Action logAccess = () -> log.debug("Retrieve schema in '{}' gateway for type '{}' in '{}'", name, type, format.getName());
final Single<SchemaData> fetchSchema = this.gatewayClient.getWriteSchema(gatewaySchema.getGateway(), gatewaySchema.getType()).map(response -> {
String schema = response.getSchema();
if (format == SchemaFormat.AVRO) {
schema = graphQLToAvroConverter.convertToSchema(schema).toString();
}
return new SchemaData(schema);
});
return exists.doOnComplete(logAccess).andThen(fetchSchema);
}
use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.
the class KubernetesGatewayService method updateSchema.
@Override
public Completable updateSchema(final String name, final String graphQLSchema) {
// Check if the gateway exists or not
final Completable resourceExists = this.kubernetesManagerClient.checkDeploymentExistence(ResourcePrefix.GATEWAY, name);
// applies the definition to gateway but not persisting it yet
final Completable updateSchema = this.gatewayClient.updateSchema(name, new SchemaData(graphQLSchema));
// persisting the applied definition to the ConfigMap and update the data of the ConfigMap
final Completable updateConfigMap = this.kubernetesManagerClient.updateConfigMap(GatewayResources.getConfigMapName(name), Map.of("schema.graphql", graphQLSchema));
return resourceExists.andThen(updateSchema).andThen(updateConfigMap).onErrorResumeNext(ex -> GatewayResources.handleDefinitionCreationError(ex, name));
}
use of com.bakdata.quick.common.api.model.gateway.SchemaData in project quick by bakdata.
the class ControllerReturnSchemaTest method shouldReturnStringSchema.
@Test
void shouldReturnStringSchema() throws IOException {
final String expectedProduct = Files.readString(workingDirectory.resolve("product.graphql"));
final String expectedPurchase = Files.readString(workingDirectory.resolve("purchase.graphql"));
final HttpRequest<?> productRequest = HttpRequest.create(HttpMethod.GET, "/schema/product");
final SchemaData productResponse = this.httpClient.exchange(productRequest, Argument.of(SchemaData.class)).blockingFirst().body();
assertThat(productResponse).isNotNull().extracting(SchemaData::getSchema).asString().isEqualToIgnoringWhitespace(expectedProduct);
final HttpRequest<?> purchaseRequest = HttpRequest.create(HttpMethod.GET, "/schema/purchase");
final SchemaData purchaseResponse = this.httpClient.exchange(purchaseRequest, Argument.of(SchemaData.class)).blockingFirst().body();
assertThat(purchaseResponse).isNotNull().extracting(SchemaData::getSchema).asString().isEqualToIgnoringWhitespace(expectedPurchase);
}
Aggregations