forked from graphql-java-kickstart/graphql-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/505-input-prefix
- Loading branch information
Showing
11 changed files
with
164 additions
and
14 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
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
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
64 changes: 64 additions & 0 deletions
64
.../graphql/annotations/GraphQLInterfaceQueryIgnoreAbstractInterfaceImplementationsTest.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,64 @@ | ||
package graphql.kickstart.graphql.annotations; | ||
|
||
import com.graphql.spring.boot.test.GraphQLResponse; | ||
import com.graphql.spring.boot.test.GraphQLTestTemplate; | ||
import graphql.kickstart.graphql.annotations.test.interfaces.Car; | ||
import graphql.kickstart.graphql.annotations.test.interfaces.Truck; | ||
import graphql.schema.GraphQLNamedType; | ||
import graphql.schema.GraphQLScalarType; | ||
import graphql.schema.GraphQLSchema; | ||
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.test.context.ActiveProfiles; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DisplayName("Testing interface handling (ignore abstract implementations).") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = "graphql.annotations.ignore-abstract-interface-implementations=true") | ||
@ActiveProfiles({"test", "interface-test"}) | ||
class GraphQLInterfaceQueryIgnoreAbstractInterfaceImplementationsTest { | ||
|
||
@Autowired | ||
private GraphQLTestTemplate graphQLTestTemplate; | ||
|
||
@Autowired | ||
private GraphQLSchema graphQLSchema; | ||
|
||
@Test | ||
@DisplayName("Assert that GraphQL interfaces and their implementations are registered correctly.") | ||
void testInterfaceQuery() throws IOException { | ||
// WHEN | ||
final GraphQLResponse actual = graphQLTestTemplate | ||
.postForResource("queries/test-interface-query.graphql"); | ||
// THEN | ||
assertThat(actual.get("$.data.vehicles[0]", Car.class)) | ||
.usingRecursiveComparison().ignoringAllOverriddenEquals() | ||
.isEqualTo(Car.builder().numberOfSeats(4).registrationNumber("ABC-123").build()); | ||
assertThat(actual.get("$.data.vehicles[1]", Truck.class)) | ||
.usingRecursiveComparison().ignoringAllOverriddenEquals() | ||
.isEqualTo(Truck.builder().cargoWeightCapacity(12).registrationNumber("CBA-321").build()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Assert that abstract GraphQL interface implementations are excluded from the schema.") | ||
void testInterfaceImplementationDetection() { | ||
// THEN | ||
Set<String> vehicleDomainTypes = graphQLSchema.getAllTypesAsList().stream() | ||
.filter(type -> !(type instanceof GraphQLScalarType)) | ||
.map(GraphQLNamedType::getName) | ||
.filter(name -> !name.startsWith("__")) | ||
.filter(name -> !"PageInfo".equals(name)) | ||
.collect(Collectors.toSet()); | ||
// Must not contain "AbstractVehicle" | ||
assertThat(vehicleDomainTypes) | ||
.containsExactlyInAnyOrder("InterfaceQuery", "Vehicle", "Car", "Truck"); | ||
} | ||
} | ||
|
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
22 changes: 22 additions & 0 deletions
22
.../src/test/java/graphql/kickstart/graphql/annotations/test/interfaces/AbstractVehicle.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,22 @@ | ||
package graphql.kickstart.graphql.annotations.test.interfaces; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLField; | ||
import graphql.annotations.annotationTypes.GraphQLNonNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@SuperBuilder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public abstract class AbstractVehicle implements Vehicle { | ||
|
||
/** | ||
* Note that you have to repeat the annotations from the interface method! | ||
*/ | ||
@GraphQLField | ||
@GraphQLNonNull | ||
private String registrationNumber; | ||
} |
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