11package com .apollographql .federation .graphqljava ;
22
33import graphql .ExecutionResult ;
4+ import graphql .Scalars ;
45import graphql .schema .GraphQLFieldDefinition ;
6+ import graphql .schema .GraphQLScalarType ;
57import graphql .schema .GraphQLSchema ;
68import graphql .schema .GraphQLType ;
79import graphql .schema .GraphQLUnionType ;
@@ -29,7 +31,9 @@ class FederationTest {
2931 private final String interfacesSDL = TestUtils .readResource ("schemas/interfaces.graphql" );
3032 private final String isolatedSDL = TestUtils .readResource ("schemas/isolated.graphql" );
3133 private final String productSDL = TestUtils .readResource ("schemas/product.graphql" );
32- private final String printerSDL = TestUtils .readResource ("schemas/printer.graphql" );
34+ private final String printerEmptySDL = TestUtils .readResource ("schemas/printerEmpty.graphql" );
35+ private final String printerFilterSDL = TestUtils .readResource ("schemas/printerFilter.graphql" );
36+ private final String printerFilterExpectedSDL = TestUtils .readResource ("schemas/printerFilterExpected.graphql" );
3337
3438 @ Test
3539 void testEmpty () {
@@ -145,8 +149,8 @@ void testInterfacesAreCovered() {
145149 }
146150
147151 @ Test
148- void testPrinter () {
149- TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser ().parse (printerSDL );
152+ void testPrinterEmpty () {
153+ TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser ().parse (printerEmptySDL );
150154 RuntimeWiring runtimeWiring = RuntimeWiring .newRuntimeWiring ()
151155 .type ("Interface1" , typeWiring -> typeWiring
152156 .typeResolver (env -> null )
@@ -159,6 +163,41 @@ void testPrinter() {
159163 typeDefinitionRegistry ,
160164 runtimeWiring
161165 );
162- Assertions .assertEquals (printerSDL .trim (), new FederationSdlPrinter ().print (graphQLSchema ).trim ());
166+ Assertions .assertEquals (printerEmptySDL .trim (), new FederationSdlPrinter ().print (graphQLSchema ).trim ());
167+ }
168+
169+ @ Test
170+ void testPrinterFilter () {
171+ TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser ().parse (printerFilterSDL );
172+ RuntimeWiring runtimeWiring = RuntimeWiring .newRuntimeWiring ()
173+ .type ("Interface1" , typeWiring -> typeWiring
174+ .typeResolver (env -> null )
175+ )
176+ .type ("Interface2" , typeWiring -> typeWiring
177+ .typeResolver (env -> null )
178+ )
179+ .scalar (GraphQLScalarType .newScalar ()
180+ .name ("Scalar1" )
181+ .coercing (Scalars .GraphQLString .getCoercing ())
182+ .build ()
183+ )
184+ .scalar (GraphQLScalarType .newScalar ()
185+ .name ("Scalar2" )
186+ .coercing (Scalars .GraphQLString .getCoercing ())
187+ .build ()
188+ )
189+ .build ();
190+ GraphQLSchema graphQLSchema = new SchemaGenerator ().makeExecutableSchema (
191+ typeDefinitionRegistry ,
192+ runtimeWiring
193+ );
194+ Assertions .assertEquals (
195+ printerFilterExpectedSDL .trim (),
196+ new FederationSdlPrinter (FederationSdlPrinter .Options .defaultOptions ()
197+ .includeScalarTypes (true )
198+ .includeDirectiveDefinitions (def -> !def .getName ().endsWith ("1" ))
199+ .includeTypeDefinitions (def -> !def .getName ().endsWith ("1" ))
200+ ).print (graphQLSchema ).trim ()
201+ );
163202 }
164203}
0 commit comments