-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3656] Add the ability to customize the GraphQL type resolver
Bug: #3656 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
4f3b627
commit 486c28b
Showing
7 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ql-api/src/main/java/org/eclipse/sirius/components/graphql/api/ITypeResolverDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* 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 graphql.TypeResolutionEnvironment; | ||
import graphql.schema.GraphQLObjectType; | ||
|
||
/** | ||
* Used to find GraphQL object type not found by the reflective type resolver. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
public interface ITypeResolverDelegate { | ||
GraphQLObjectType getType(TypeResolutionEnvironment environment); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...rius-web/src/test/java/org/eclipse/sirius/web/application/services/TypeResolverTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.services; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.infrastructure.graphql.GraphQLWiringFactory; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import graphql.GraphQL; | ||
import graphql.execution.TypeResolutionParameters; | ||
import graphql.schema.idl.InterfaceWiringEnvironment; | ||
|
||
/** | ||
* Used to test the GraphQL type resolution. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Transactional | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class TypeResolverTests extends AbstractIntegrationTests { | ||
|
||
@Autowired | ||
private GraphQLWiringFactory graphQLWiringFactory; | ||
|
||
@Autowired | ||
private GraphQL graphQL; | ||
|
||
@Test | ||
@DisplayName("Given the type resolver, when asked for a unknown type, then the expected type is returned") | ||
public void givenTheTypeResolverWhenAskedForUnknownTypeThenTheExpectedTypeIsReturned() { | ||
var environment = TypeResolutionParameters.newParameters() | ||
.schema(this.graphQL.getGraphQLSchema()) | ||
.value(this) | ||
.build(); | ||
|
||
var typeResolver = this.graphQLWiringFactory.getTypeResolver((InterfaceWiringEnvironment) null); | ||
var graphQLObjectType = typeResolver.getType(environment); | ||
assertThat(graphQLObjectType.getName()).isEqualTo("Diagram"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...nd/sirius-web/src/test/java/org/eclipse/sirius/web/services/TestTypeResolverDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.services; | ||
|
||
import org.eclipse.sirius.components.graphql.api.ITypeResolverDelegate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import graphql.TypeResolutionEnvironment; | ||
import graphql.schema.GraphQLObjectType; | ||
|
||
/** | ||
* Used during tests to return a GraphQL object type for unknown objects. | ||
* | ||
* @author sbegaudeau | ||
*/ | ||
@Service | ||
public class TestTypeResolverDelegate implements ITypeResolverDelegate { | ||
@Override | ||
public GraphQLObjectType getType(TypeResolutionEnvironment environment) { | ||
return environment.getSchema().getObjectType("Diagram"); | ||
} | ||
} |