Skip to content

Commit

Permalink
[3156] Make Viewer a type instead of an interface in our GraphQL API
Browse files Browse the repository at this point in the history
Bug: #3156
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Feb 26, 2024
1 parent c9e5a13 commit 9b8f017
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 355 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -58,6 +58,8 @@ It's current location is only there to simplify the transition to the new Sirius
- https://github.com/eclipse-sirius/sirius-web/issues/3019[#3019] [emf] Remove the dependency from `sirius-components-emf` to the validation representation.
Reusing the EMF compatibility layer will not add any dependency to specific representations.
The EMF validation support will now be provided by `sirius-web-services`.
- https://github.com/eclipse-sirius/sirius-web/issues/3156[#3156] [core] In our GraphQL schema, `Viewer` is now a type instead of an interface.
Having `Viewer` as a type did not bring any additional value and it created some overhead by having to create and keep updated an additional type without any benefit.


=== Dependency update
Expand Down
Expand Up @@ -5,9 +5,7 @@ type Query {
viewer: Viewer!
}

interface Viewer {
id: ID!
username: String!
type Viewer {
editingContext(editingContextId: ID!): EditingContext
}

Expand Down
Expand Up @@ -29,7 +29,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "DefaultViewer", field = "editingContext")
@QueryDataFetcher(type = "Viewer", field = "editingContext")
public class ViewerEditingContextDataFetcher implements IDataFetcherWithFieldCoordinates<DataFetcherResult<String>> {

private static final String EDITING_CONTEXT_ID_ARGUMENT = "editingContextId";
Expand Down
Expand Up @@ -27,7 +27,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "DefaultViewer", field = "project")
@QueryDataFetcher(type = "Viewer", field = "project")
public class ViewerProjectDataFetcher implements IDataFetcherWithFieldCoordinates<ProjectDTO> {

private static final String PROJECT_ID_ARGUMENT = "projectId";
Expand Down
Expand Up @@ -37,7 +37,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "DefaultViewer", field = "projectTemplates")
@QueryDataFetcher(type = "Viewer", field = "projectTemplates")
public class ViewerProjectTemplatesDataFetcher implements IDataFetcherWithFieldCoordinates<Connection<ProjectTemplateDTO>> {

private static final String PAGE_ARGUMENT = "page";
Expand Down
Expand Up @@ -37,7 +37,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "DefaultViewer", field = "projects")
@QueryDataFetcher(type = "Viewer", field = "projects")
public class ViewerProjectsDataFetcher implements IDataFetcherWithFieldCoordinates<Connection<ProjectDTO>> {

private static final String PAGE_ARGUMENT = "page";
Expand Down

This file was deleted.

Expand Up @@ -18,10 +18,10 @@

import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.SuccessPayload;
import org.eclipse.sirius.web.application.project.dto.CreateProjectInput;
import org.eclipse.sirius.web.application.project.dto.CreateProjectSuccessPayload;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectInput;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectSuccessPayload;
import org.eclipse.sirius.web.application.project.dto.ProjectDTO;
import org.eclipse.sirius.web.application.project.dto.RenameProjectInput;
import org.eclipse.sirius.web.application.project.dto.RenameProjectSuccessPayload;
Expand Down Expand Up @@ -113,7 +113,7 @@ public IPayload deleteProject(DeleteProjectInput input) {
if (result instanceof Failure<Void> failure) {
payload = new ErrorPayload(input.id(), failure.message());
} else if (result instanceof Success<Void>) {
payload = new DeleteProjectSuccessPayload(input.id());
payload = new SuccessPayload(input.id());
}
return payload;
}
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -14,8 +14,6 @@

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.application.viewer.IViewer;
import org.eclipse.sirius.web.application.viewer.DefaultViewer;

import graphql.schema.DataFetchingEnvironment;

Expand All @@ -25,9 +23,9 @@
* @author sbegaudeau
*/
@QueryDataFetcher(type = "Query", field = "viewer")
public class QueryViewDataFetcher implements IDataFetcherWithFieldCoordinates<IViewer> {
public class QueryViewerDataFetcher implements IDataFetcherWithFieldCoordinates<Object> {
@Override
public IViewer get(DataFetchingEnvironment environment) throws Exception {
return new DefaultViewer();
public Object get(DataFetchingEnvironment environment) throws Exception {
return new Object();
}
}
@@ -1,10 +1,9 @@
extend interface Viewer {
extend type Viewer {
project(projectId: ID!): Project
projects(page: Int!, limit: Int!): ViewerProjectsConnection!
projectTemplates(page: Int!, limit: Int!): ViewerProjectTemplatesConnection!
}


type ViewerProjectsConnection {
edges: [ViewerProjectsEdge!]!
pageInfo: PageInfo!
Expand Down Expand Up @@ -35,15 +34,6 @@ type ProjectTemplate {
imageURL: String!
}

type DefaultViewer implements Viewer {
id: ID!
username: String!
editingContext(editingContextId: ID!): EditingContext
project(projectId: ID!): Project
projects(page: Int!, limit: Int!): ViewerProjectsConnection!
projectTemplates(page: Int!, limit: Int!): ViewerProjectTemplatesConnection!
}

extend type Mutation {
createProject(input: CreateProjectInput!): CreateProjectPayload!
renameProject(input: RenameProjectInput!): RenameProjectPayload!
Expand Down Expand Up @@ -80,11 +70,7 @@ input DeleteProjectInput {
projectId: ID!
}

union DeleteProjectPayload = ErrorPayload | DeleteProjectSuccessPayload

type DeleteProjectSuccessPayload {
id: ID!
}
union DeleteProjectPayload = ErrorPayload | SuccessPayload

extend type Subscription {
projectEvent(input: ProjectEventInput!): ProjectEventPayload!
Expand Down

This file was deleted.

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 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 @@ -13,19 +13,17 @@
package org.eclipse.sirius.web.graphql.datafetchers.mutation;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.core.api.ErrorPayload;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.SuccessPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.graphql.datafetchers.IViewerProvider;
import org.eclipse.sirius.web.graphql.messages.IGraphQLMessageService;
import org.eclipse.sirius.web.services.api.projects.DeleteProjectInput;
import org.eclipse.sirius.web.services.api.projects.DeleteProjectSuccessPayload;
import org.eclipse.sirius.web.services.api.projects.IProjectService;
import org.eclipse.sirius.web.services.api.viewer.IViewer;

import graphql.schema.DataFetchingEnvironment;

Expand All @@ -52,37 +50,24 @@ public class MutationDeleteProjectDataFetcher implements IDataFetcherWithFieldCo

private final ObjectMapper objectMapper;

private final IViewerProvider viewerProvider;

private final IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry;

private final IProjectService projectService;

private final IGraphQLMessageService messageService;

public MutationDeleteProjectDataFetcher(ObjectMapper objectMapper, IViewerProvider viewerProvider, IProjectService projectService,
public MutationDeleteProjectDataFetcher(ObjectMapper objectMapper, IProjectService projectService,
IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry, IGraphQLMessageService messageService) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.viewerProvider = Objects.requireNonNull(viewerProvider);
this.projectService = Objects.requireNonNull(projectService);
this.editingContextEventProcessorRegistry = Objects.requireNonNull(editingContextEventProcessorRegistry);
this.messageService = Objects.requireNonNull(messageService);
}

@Override
public IPayload get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, DeleteProjectInput.class);

var optionalViewer = this.viewerProvider.getViewer(environment);
IPayload payload = new ErrorPayload(input.id(), this.messageService.unexpectedError());
if (optionalViewer.isPresent()) {
IViewer viewer = optionalViewer.get();
this.editingContextEventProcessorRegistry.disposeEditingContextEventProcessor(input.projectId().toString());
this.projectService.delete(input.projectId());
payload = new DeleteProjectSuccessPayload(input.id(), viewer);
}

return payload;
this.editingContextEventProcessorRegistry.disposeEditingContextEventProcessor(input.projectId().toString());
this.projectService.delete(input.projectId());
return new SuccessPayload(input.id());
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 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 @@ -12,12 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.web.graphql.datafetchers.query;

import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.graphql.datafetchers.IViewerProvider;
import org.eclipse.sirius.web.services.api.viewer.IViewer;

import graphql.schema.DataFetchingEnvironment;

Expand All @@ -36,16 +32,10 @@
* @author sbegaudeau
*/
@QueryDataFetcher(type = "Query", field = "viewer")
public class QueryViewerDataFetcher implements IDataFetcherWithFieldCoordinates<IViewer> {

private final IViewerProvider viewerProvider;

public QueryViewerDataFetcher(IViewerProvider viewerProvider) {
this.viewerProvider = Objects.requireNonNull(viewerProvider);
}
public class QueryViewerDataFetcher implements IDataFetcherWithFieldCoordinates<Object> {

@Override
public IViewer get(DataFetchingEnvironment environment) throws Exception {
return this.viewerProvider.getViewer(environment).orElse(null);
public Object get(DataFetchingEnvironment environment) throws Exception {
return new Object();
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* Copyright (c) 2021, 2024 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.web.graphql.datafetchers.user;
package org.eclipse.sirius.web.graphql.datafetchers.viewer;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -29,15 +29,15 @@
* </p>
*
* <pre>
* type User {
* type Viewer {
* editingContext(editingContextId: ID!): EditingContext
* }
* </pre>
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "User", field = "editingContext")
public class UserEditingContextDataFetcher implements IDataFetcherWithFieldCoordinates<DataFetcherResult<String>> {
@QueryDataFetcher(type = "Viewer", field = "editingContext")
public class ViewerEditingContextDataFetcher implements IDataFetcherWithFieldCoordinates<DataFetcherResult<String>> {
private static final String EDITING_CONTEXT_ID_ARGUMENT = "editingContextId";

@Override
Expand Down

0 comments on commit 9b8f017

Please sign in to comment.