Skip to content

Commit

Permalink
[1312] Provide the validation GraphQL datafetchers
Browse files Browse the repository at this point in the history
Bug: #1312
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jul 28, 2022
1 parent d33f718 commit 9752073
Show file tree
Hide file tree
Showing 37 changed files with 489 additions and 96 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -7,6 +7,7 @@
- https://github.com/eclipse-sirius/sirius-components/issues/1311[#1311] [releng] Allow reusing `sirius-components-emf` without dependencies to the domain or view DSL. As a result, two new projects `sirius-components-domain-emf` and `sirius-components-view-emf` have been introduced in order to connect the EMF compatibility layer with the domain and view DSL. Consumers of `sirius-components-emf` may have to update their import. The behavior of the code has not been modified
- https://github.com/eclipse-sirius/sirius-components/issues/1311[#1311] [releng] Allow reusing `sirius-component-emf` without dependencies to Sirius Desktop. As a result, a new project `sirius-components-compatibility-emf` has been added in order to provide EMF support for the Sirius desktop compatibility layer. Consumers of `sirius-components-emf` may have to update their import. The behavior of the code has not been modified
- https://github.com/eclipse-sirius/sirius-components/issues/1237[#1237] [releng] Remove the two hardcoded dependencies to Spring MVC from Sirius Components. As such, reusing most components from Sirius Components without Spring MVC will be easier. The only projects with a dependency to Spring MVC are located in the `web` package
- https://github.com/eclipse-sirius/sirius-components/issues/1312[#1312] [graphql] Provide the datafetchers used by the representations. Starting with the validation representation, we will provide datafetchers directly in Sirius Components to simplify the integration of Sirius Components in various applications. The project `sirius-components-graphql-utils` has been merged into `sirius-components-graphql-utils` since they had similar dependencies.


=== Improvements
Expand Down
14 changes: 14 additions & 0 deletions packages/core/backend/sirius-components-graphql-api/pom.xml
Expand Up @@ -46,11 +46,25 @@
<artifactId>graphql-java</artifactId>
<version>${graphql-java.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-annotations-spring</artifactId>
<version>2022.7.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-core</artifactId>
<version>2022.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-collaborative</artifactId>
<version>2022.7.0</version>
</dependency>
</dependencies>

<build>
Expand Down
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.graphql.api;

import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;

import reactor.core.publisher.Flux;

/**
* Used to retrieve subscriptions.
*
* @author sbegaudeau
*/
public interface IEventProcessorSubscriptionProvider {
<T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String editingContextId, Class<T> representationEventProcessorClass,
IRepresentationConfiguration representationConfiguration, IInput input);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
* @author sbegaudeau
*/
class NoOp implements IEventProcessorSubscriptionProvider {

@Override
public <T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String editingContextId, Class<T> representationEventProcessorClass,
IRepresentationConfiguration representationConfiguration, IInput input) {
return Flux.empty();
}

}
}
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.graphql.api;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;

import graphql.relay.Connection;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* Used to encapsulate calls to methods which may throw exceptions. This wrapper will make sure that a default result is
* properly returned instead of having to repeat a default response in all the data fetchers.
*
* @author sbegaudeau
*/
public interface IExceptionWrapper {
Flux<IPayload> wrapFlux(Supplier<Flux<IPayload>> supplier, IInput input);

IPayload wrap(Supplier<IPayload> supplier, IInput input);

<T> List<T> wrapList(Supplier<List<T>> supplier);

<T> Optional<T> wrapOptional(Supplier<Optional<T>> supplier);

<T> Connection<T> wrapConnection(Supplier<Connection<T>> supplier);

Mono<IPayload> wrapMono(Supplier<Mono<IPayload>> supplier, IInput input);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
* @author sbegaudeau
*/
class NoOp implements IExceptionWrapper {

@Override
public Flux<IPayload> wrapFlux(Supplier<Flux<IPayload>> supplier, IInput input) {
return Flux.empty();
}

@Override
public IPayload wrap(Supplier<IPayload> supplier, IInput input) {
return null;
}

@Override
public <T> List<T> wrapList(Supplier<List<T>> supplier) {
return List.of();
}

@Override
public <T> Optional<T> wrapOptional(Supplier<Optional<T>> supplier) {
return Optional.empty();
}

@Override
public <T> Connection<T> wrapConnection(Supplier<Connection<T>> supplier) {
return null;
}

@Override
public Mono<IPayload> wrapMono(Supplier<Mono<IPayload>> supplier, IInput input) {
return Mono.empty();
}

}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.graphql.utils.typeresolvers;
package org.eclipse.sirius.components.graphql.api;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.graphql.utils.types;
package org.eclipse.sirius.components.graphql.api;

import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.graphql.utils.types;
package org.eclipse.sirius.components.graphql.api;

import graphql.schema.GraphQLScalarType;

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions packages/core/backend/sirius-components-graphql-utils/README.adoc

This file was deleted.

10 changes: 5 additions & 5 deletions packages/releng/backend/sirius-components-test-coverage/pom.xml
Expand Up @@ -120,11 +120,6 @@
<artifactId>sirius-components-forms</artifactId>
<version>2022.7.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-graphql-utils</artifactId>
<version>2022.7.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-interpreter</artifactId>
Expand Down Expand Up @@ -175,6 +170,11 @@
<artifactId>sirius-components-collaborative-validation</artifactId>
<version>2022.7.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-validation-graphql</artifactId>
<version>2022.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-graphql</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions packages/starters/backend/sirius-components-starter/pom.xml
Expand Up @@ -115,6 +115,11 @@
<artifactId>sirius-components-collaborative-validation</artifactId>
<version>2022.7.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-validation-graphql</artifactId>
<version>2022.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-components-emf</artifactId>
Expand Down
Expand Up @@ -14,12 +14,20 @@

import java.util.concurrent.Executors;

import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.components.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.components.collaborative.editingcontext.api.IEditingContextEventProcessorExecutorServiceProvider;
import org.eclipse.sirius.components.collaborative.forms.WidgetSubscriptionManager;
import org.eclipse.sirius.components.collaborative.forms.api.IWidgetSubscriptionManagerFactory;
import org.eclipse.sirius.components.collaborative.representations.SubscriptionManager;
import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IEventProcessorSubscriptionProvider;
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper;
import org.eclipse.sirius.components.graphql.ws.api.IGraphQLWebSocketHandlerListener;
import org.eclipse.sirius.components.starter.services.ExceptionWrapper;
import org.eclipse.sirius.components.web.concurrent.DelegatingRequestContextExecutorService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
Expand All @@ -30,6 +38,8 @@
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import reactor.core.publisher.Flux;

/**
* Projects which depend on this starter project will automatically get all the components required to create a Sirius
* Web application.
Expand Down Expand Up @@ -98,4 +108,27 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus status)
}
};
}

@Bean
@ConditionalOnMissingBean
public IEventProcessorSubscriptionProvider eventProcessorSubscriptionProvider(IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry) {
return new IEventProcessorSubscriptionProvider() {
@Override
public <T extends IRepresentationEventProcessor> Flux<IPayload> getSubscription(String editingContextId, Class<T> representationEventProcessorClass,
IRepresentationConfiguration representationConfiguration, IInput input) {
// @formatter:off
return editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(editingContextId)
.flatMap(processor -> processor.acquireRepresentationEventProcessor(representationEventProcessorClass, representationConfiguration, input))
.map(representationEventProcessor -> representationEventProcessor.getOutputEvents(input))
.orElse(Flux.empty());
// @formatter:on
}
};
}

@Bean
@ConditionalOnMissingBean
public IExceptionWrapper exceptionWrapper() {
return new ExceptionWrapper();
}
}
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.starter.services;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import org.eclipse.sirius.components.core.api.IInput;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IExceptionWrapper;

import graphql.relay.Connection;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* Used to encapsulate calls to methods which can throw exceptions.
*
* @author sbegaudeau
*/
public class ExceptionWrapper implements IExceptionWrapper {

@Override
public Flux<IPayload> wrapFlux(Supplier<Flux<IPayload>> supplier, IInput input) {
return supplier.get();
}

@Override
public IPayload wrap(Supplier<IPayload> supplier, IInput input) {
return supplier.get();
}

@Override
public <T> List<T> wrapList(Supplier<List<T>> supplier) {
return supplier.get();
}

@Override
public <T> Optional<T> wrapOptional(Supplier<Optional<T>> supplier) {
return supplier.get();
}

@Override
public <T> Connection<T> wrapConnection(Supplier<Connection<T>> supplier) {
return supplier.get();
}

@Override
public Mono<IPayload> wrapMono(Supplier<Mono<IPayload>> supplier, IInput input) {
return supplier.get();
}

}

0 comments on commit 9752073

Please sign in to comment.