Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql-java-support: Fix grammar violation in graphql-java's SchemaPrinter #52

Merged
merged 9 commits into from
Mar 19, 2020

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLType;
import graphql.schema.TypeResolver;
import graphql.schema.idl.SchemaPrinter;
import graphql.schema.idl.errors.SchemaProblem;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -139,11 +138,11 @@ public final GraphQLSchema build() throws SchemaProblem {
}

private String sdl() {
final SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions()
final FederationSdlPrinter.Options options = FederationSdlPrinter.Options.defaultOptions()
sachindshinde marked this conversation as resolved.
Show resolved Hide resolved
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeSchemaDefintion(true)
.includeDirectives(true);
return new SchemaPrinter(options).print(originalSchema);
return new FederationSdlPrinter(options).print(originalSchema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import graphql.schema.GraphQLType;
import graphql.schema.GraphQLUnionType;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.schema.idl.TypeRuntimeWiring;
import graphql.schema.idl.errors.SchemaProblem;
import org.junit.jupiter.api.Assertions;
Expand All @@ -26,6 +29,7 @@ class FederationTest {
private final String interfacesSDL = TestUtils.readResource("schemas/interfaces.graphql");
private final String isolatedSDL = TestUtils.readResource("schemas/isolated.graphql");
private final String productSDL = TestUtils.readResource("schemas/product.graphql");
private final String printerSDL = TestUtils.readResource("schemas/printer.graphql");

@Test
void testEmpty() {
Expand Down Expand Up @@ -127,4 +131,22 @@ void testInterfacesAreCovered() {

assertIterableEquals(Arrays.asList("Book", "Movie", "Page"), unionTypes);
}

@Test
void testPrinter() {
TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(printerSDL);
RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
.type("Interface1", typeWiring -> typeWiring
.typeResolver(env -> null)
)
.type("Interface2", typeWiring -> typeWiring
.typeResolver(env -> null)
)
.build();
GraphQLSchema graphQLSchema = new SchemaGenerator().makeExecutableSchema(
typeDefinitionRegistry,
runtimeWiring
);
Assertions.assertEquals(printerSDL.trim(), new FederationSdlPrinter().print(graphQLSchema).trim());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import graphql.ExecutionResult;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.SchemaPrinter;

import java.util.Map;

Expand All @@ -17,7 +16,7 @@ private SchemaUtils() {
}

static String printSchema(GraphQLSchema schema) {
return new SchemaPrinter().print(schema);
return new FederationSdlPrinter().print(schema);
}

static ExecutionResult execute(GraphQLSchema schema, String query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ schema {
query: Query
}

type Query {
}
type Query
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
type Query {
}
type Query

type SomeType @key(fields: "theKey") {
theKey: ID!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
interface Interface1

interface Interface2 {
dummy: String
}

type Object1

type Object2 {
dummy: String
}

type Query

enum Enum1

enum Enum2 {
DUMMY
}

input InputObject1

input InputObject2 {
dummy: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ type Product @key(fields : "upc") {
upc: String!
}

type Query {
}
type Query