Skip to content

Commit

Permalink
Merge pull request #51 from apollographql/sachin/graphql-java-v14
Browse files Browse the repository at this point in the history
graphql-java-support: Bump graphql-java to v14
  • Loading branch information
sachindshinde committed Mar 27, 2020
2 parents eba141b + 3a0c369 commit da23efa
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private static RuntimeWiring.Builder copyRuntimeWiring(RuntimeWiring runtimeWiri
runtimeWiring.getRegisteredDirectiveWiring().forEach(builder::directive);
runtimeWiring.getDirectiveWiring().forEach(builder::directiveWiring);
builder.comparatorRegistry(runtimeWiring.getComparatorRegistry());
runtimeWiring.getSchemaTransformers().forEach(builder::transformer);
runtimeWiring.getSchemaGeneratorPostProcessings().forEach(builder::transformer);

return builder;
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLDirectiveContainer;
import graphql.schema.GraphQLNamedType;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLType;
Expand All @@ -15,13 +16,17 @@
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public final class SchemaTransformer {
private static final Object DUMMY = new Object();
// Apollo Gateway will fail composition if it sees standard directive definitions.
private static final Set<String> STANDARD_DIRECTIVES =
new HashSet<>(Arrays.asList("deprecated", "include", "skip"));
private final GraphQLSchema originalSchema;
private TypeResolver entityTypeResolver = null;
private DataFetcher entitiesDataFetcher = null;
Expand Down Expand Up @@ -88,7 +93,7 @@ public final GraphQLSchema build() throws SchemaProblem {
final Set<String> entityTypeNames = originalSchema.getAllTypesAsList().stream()
.filter(t -> t instanceof GraphQLDirectiveContainer &&
((GraphQLDirectiveContainer) t).getDirective(FederationDirectives.keyName) != null)
.map(GraphQLType::getName)
.map(GraphQLNamedType::getName)
.collect(Collectors.toSet());

final Set<String> entityConcreteTypeNames = originalSchema.getAllTypesAsList()
Expand All @@ -98,7 +103,7 @@ public final GraphQLSchema build() throws SchemaProblem {
((GraphQLObjectType) type).getInterfaces()
.stream()
.anyMatch(itf -> entityTypeNames.contains(itf.getName())))
.map(GraphQLType::getName)
.map(GraphQLNamedType::getName)
.collect(Collectors.toSet());

// If there are entity types install: Query._entities(representations: [_Any!]!): [_Entity]!
Expand Down Expand Up @@ -140,7 +145,9 @@ public final GraphQLSchema build() throws SchemaProblem {

public static String sdl(GraphQLSchema schema) {
// Gather directive definitions to hide.
final Set<String> hiddenDirectiveDefinitions = new HashSet<>(FederationDirectives.allNames);
final Set<String> hiddenDirectiveDefinitions = new HashSet<>();
hiddenDirectiveDefinitions.addAll(STANDARD_DIRECTIVES);
hiddenDirectiveDefinitions.addAll(FederationDirectives.allNames);

// Gather type definitions to hide.
final Set<String> hiddenTypeDefinitions = new HashSet<>();
Expand All @@ -162,7 +169,7 @@ public static String sdl(GraphQLSchema schema) {
final FederationSdlPrinter.Options options = FederationSdlPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeSchemaDefintion(true)
.includeSchemaDefinition(true)
.includeDirectives(true)
.includeDirectiveDefinitions(def -> !hiddenDirectiveDefinitions.contains(def.getName()))
.includeTypeDefinitions(def -> !hiddenTypeDefinitions.contains(def.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import graphql.ExecutionResult;
import graphql.Scalars;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLNamedType;
import graphql.schema.GraphQLScalarType;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLType;
Expand All @@ -17,8 +18,10 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -34,6 +37,8 @@ class FederationTest {
private final String printerEmptySDL = TestUtils.readResource("schemas/printerEmpty.graphql");
private final String printerFilterSDL = TestUtils.readResource("schemas/printerFilter.graphql");
private final String printerFilterExpectedSDL = TestUtils.readResource("schemas/printerFilterExpected.graphql");
private final Set<String> standardDirectives =
new HashSet<>(Arrays.asList("deprecated", "include", "skip"));

@Test
void testEmpty() {
Expand All @@ -57,7 +62,12 @@ void testEmpty() {
" sdl: String!\n" +
"}\n" +
"\n" +
"scalar _FieldSet\n", SchemaUtils.printSchema(federated));
"scalar _FieldSet\n",
new FederationSdlPrinter(FederationSdlPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeDirectiveDefinitions(def -> !standardDirectives.contains(def.getName()))
).print(federated)
);

final GraphQLType _Service = federated.getType("_Service");
assertNotNull(_Service, "_Service type present");
Expand Down Expand Up @@ -141,7 +151,7 @@ void testInterfacesAreCovered() {
final Iterable<String> unionTypes = entityType
.getTypes()
.stream()
.map(GraphQLType::getName)
.map(GraphQLNamedType::getName)
.sorted()
.collect(Collectors.toList());

Expand All @@ -163,7 +173,12 @@ void testPrinterEmpty() {
typeDefinitionRegistry,
runtimeWiring
);
Assertions.assertEquals(printerEmptySDL.trim(), new FederationSdlPrinter().print(graphQLSchema).trim());
Assertions.assertEquals(
printerEmptySDL.trim(),
new FederationSdlPrinter(FederationSdlPrinter.Options.defaultOptions()
.includeDirectiveDefinitions(def -> !standardDirectives.contains(def.getName()))
).print(graphQLSchema).trim()
);
}

@Test
Expand Down Expand Up @@ -195,7 +210,9 @@ void testPrinterFilter() {
printerFilterExpectedSDL.trim(),
new FederationSdlPrinter(FederationSdlPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeDirectiveDefinitions(def -> !def.getName().endsWith("1"))
.includeDirectiveDefinitions(def ->
!def.getName().endsWith("1") && !standardDirectives.contains(def.getName())
)
.includeTypeDefinitions(def -> !def.getName().endsWith("1"))
).print(graphQLSchema).trim()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ final class SchemaUtils {
private SchemaUtils() {
}

static String printSchema(GraphQLSchema schema) {
return new FederationSdlPrinter(FederationSdlPrinter.Options.defaultOptions()
.includeScalarTypes(true)
).print(schema);
}

static ExecutionResult execute(GraphQLSchema schema, String query) {
return newGraphQL(schema).build().execute(newExecutionInput().query(query).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ schema {

type Money {
amount: Int!
currencyCode: String!
currencyCode: String! @deprecated(reason : "dummy")
}

type Product @key(fields : "upc") {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
<graphql-java.version>13.0</graphql-java.version>
<graphql-java.version>14.0</graphql-java.version>
<graphql-spring-boot.version>5.10.0</graphql-spring-boot.version>
<java.version>1.8</java.version>
<jetbrains-annotations.version>17.0.0</jetbrains-annotations.version>
Expand Down

0 comments on commit da23efa

Please sign in to comment.