@@ -98,6 +98,8 @@ public static class Options {
9898
9999 private final boolean descriptionsAsHashComments ;
100100
101+ private final Predicate <String > includeDirectiveDefinition ;
102+
101103 private final Predicate <String > includeDirective ;
102104
103105 private final Predicate <GraphQLSchemaElement > includeSchemaElement ;
@@ -110,6 +112,7 @@ private Options(boolean includeIntrospectionTypes,
110112 boolean includeScalars ,
111113 boolean includeSchemaDefinition ,
112114 boolean includeDirectiveDefinitions ,
115+ Predicate <String > includeDirectiveDefinition ,
113116 boolean useAstDefinitions ,
114117 boolean descriptionsAsHashComments ,
115118 Predicate <String > includeDirective ,
@@ -120,6 +123,7 @@ private Options(boolean includeIntrospectionTypes,
120123 this .includeScalars = includeScalars ;
121124 this .includeSchemaDefinition = includeSchemaDefinition ;
122125 this .includeDirectiveDefinitions = includeDirectiveDefinitions ;
126+ this .includeDirectiveDefinition = includeDirectiveDefinition ;
123127 this .includeDirective = includeDirective ;
124128 this .useAstDefinitions = useAstDefinitions ;
125129 this .descriptionsAsHashComments = descriptionsAsHashComments ;
@@ -144,6 +148,10 @@ public boolean isIncludeDirectiveDefinitions() {
144148 return includeDirectiveDefinitions ;
145149 }
146150
151+ public Predicate <String > getIncludeDirectiveDefinition () {
152+ return includeDirectiveDefinition ;
153+ }
154+
147155 public Predicate <String > getIncludeDirective () {
148156 return includeDirective ;
149157 }
@@ -164,14 +172,16 @@ public boolean isUseAstDefinitions() {
164172 return useAstDefinitions ;
165173 }
166174
167- public boolean isIncludeAstDefinitionComments () { return includeAstDefinitionComments ; }
175+ public boolean isIncludeAstDefinitionComments () {
176+ return includeAstDefinitionComments ;
177+ }
168178
169179 public static Options defaultOptions () {
170180 return new Options (false ,
171181 true ,
172182 false ,
173183 true ,
174- false ,
184+ directive -> true , false ,
175185 false ,
176186 directive -> true ,
177187 element -> true ,
@@ -191,7 +201,7 @@ public Options includeIntrospectionTypes(boolean flag) {
191201 this .includeScalars ,
192202 this .includeSchemaDefinition ,
193203 this .includeDirectiveDefinitions ,
194- this .useAstDefinitions ,
204+ this .includeDirectiveDefinition , this . useAstDefinitions ,
195205 this .descriptionsAsHashComments ,
196206 this .includeDirective ,
197207 this .includeSchemaElement ,
@@ -211,7 +221,7 @@ public Options includeScalarTypes(boolean flag) {
211221 flag ,
212222 this .includeSchemaDefinition ,
213223 this .includeDirectiveDefinitions ,
214- this .useAstDefinitions ,
224+ this .includeDirectiveDefinition , this . useAstDefinitions ,
215225 this .descriptionsAsHashComments ,
216226 this .includeDirective ,
217227 this .includeSchemaElement ,
@@ -234,6 +244,7 @@ public Options includeSchemaDefinition(boolean flag) {
234244 this .includeScalars ,
235245 flag ,
236246 this .includeDirectiveDefinitions ,
247+ this .includeDirectiveDefinition ,
237248 this .useAstDefinitions ,
238249 this .descriptionsAsHashComments ,
239250 this .includeDirective ,
@@ -259,6 +270,29 @@ public Options includeDirectiveDefinitions(boolean flag) {
259270 this .includeScalars ,
260271 this .includeSchemaDefinition ,
261272 flag ,
273+ directive -> flag ,
274+ this .useAstDefinitions ,
275+ this .descriptionsAsHashComments ,
276+ this .includeDirective ,
277+ this .includeSchemaElement ,
278+ this .comparatorRegistry ,
279+ this .includeAstDefinitionComments );
280+ }
281+
282+
283+ /**
284+ * This is a Predicate that decides whether a directive definition is printed.
285+ *
286+ * @param includeDirectiveDefinition the predicate to decide of a directive defintion is printed
287+ *
288+ * @return new instance of options
289+ */
290+ public Options includeDirectiveDefinition (Predicate <String > includeDirectiveDefinition ) {
291+ return new Options (this .includeIntrospectionTypes ,
292+ this .includeScalars ,
293+ this .includeSchemaDefinition ,
294+ this .includeDirectiveDefinitions ,
295+ includeDirectiveDefinition ,
262296 this .useAstDefinitions ,
263297 this .descriptionsAsHashComments ,
264298 this .includeDirective ,
@@ -280,6 +314,7 @@ public Options includeDirectives(boolean flag) {
280314 this .includeScalars ,
281315 this .includeSchemaDefinition ,
282316 this .includeDirectiveDefinitions ,
317+ this .includeDirectiveDefinition ,
283318 this .useAstDefinitions ,
284319 this .descriptionsAsHashComments ,
285320 directive -> flag ,
@@ -300,6 +335,7 @@ public Options includeDirectives(Predicate<String> includeDirective) {
300335 this .includeScalars ,
301336 this .includeSchemaDefinition ,
302337 this .includeDirectiveDefinitions ,
338+ this .includeDirectiveDefinition ,
303339 this .useAstDefinitions ,
304340 this .descriptionsAsHashComments ,
305341 includeDirective ,
@@ -308,6 +344,7 @@ public Options includeDirectives(Predicate<String> includeDirective) {
308344 this .includeAstDefinitionComments );
309345 }
310346
347+
311348 /**
312349 * This is a general purpose Predicate that decides whether a schema element is printed ever.
313350 *
@@ -321,6 +358,7 @@ public Options includeSchemaElement(Predicate<GraphQLSchemaElement> includeSchem
321358 this .includeScalars ,
322359 this .includeSchemaDefinition ,
323360 this .includeDirectiveDefinitions ,
361+ this .includeDirectiveDefinition ,
324362 this .useAstDefinitions ,
325363 this .descriptionsAsHashComments ,
326364 this .includeDirective ,
@@ -342,6 +380,7 @@ public Options useAstDefinitions(boolean flag) {
342380 this .includeScalars ,
343381 this .includeSchemaDefinition ,
344382 this .includeDirectiveDefinitions ,
383+ this .includeDirectiveDefinition ,
345384 flag ,
346385 this .descriptionsAsHashComments ,
347386 this .includeDirective ,
@@ -365,6 +404,7 @@ public Options descriptionsAsHashComments(boolean flag) {
365404 this .includeScalars ,
366405 this .includeSchemaDefinition ,
367406 this .includeDirectiveDefinitions ,
407+ this .includeDirectiveDefinition ,
368408 this .useAstDefinitions ,
369409 flag ,
370410 this .includeDirective ,
@@ -387,6 +427,7 @@ public Options setComparators(GraphqlTypeComparatorRegistry comparatorRegistry)
387427 this .includeScalars ,
388428 this .includeSchemaDefinition ,
389429 this .includeDirectiveDefinitions ,
430+ this .includeDirectiveDefinition ,
390431 this .useAstDefinitions ,
391432 this .descriptionsAsHashComments ,
392433 this .includeDirective ,
@@ -409,6 +450,7 @@ public Options includeAstDefinitionComments(boolean flag) {
409450 this .includeScalars ,
410451 this .includeSchemaDefinition ,
411452 this .includeDirectiveDefinitions ,
453+ this .includeDirectiveDefinition ,
412454 this .useAstDefinitions ,
413455 this .descriptionsAsHashComments ,
414456 this .includeDirective ,
@@ -638,7 +680,9 @@ private SchemaElementPrinter<GraphQLUnionType> unionPrinter() {
638680
639681 private SchemaElementPrinter <GraphQLDirective > directivePrinter () {
640682 return (out , directive , visibility ) -> {
641- if (options .isIncludeDirectiveDefinitions ()) {
683+ boolean isOnEver = options .isIncludeDirectiveDefinitions ();
684+ boolean specificTest = options .getIncludeDirectiveDefinition ().test (directive .getName ());
685+ if (isOnEver && specificTest ) {
642686 String s = directiveDefinition (directive );
643687 out .format ("%s" , s );
644688 out .print ("\n \n " );
@@ -964,14 +1008,14 @@ private boolean hasDeprecatedDirective(List<GraphQLAppliedDirective> directives)
9641008
9651009 private List <GraphQLAppliedDirective > addDeprecatedDirectiveIfNeeded (GraphQLDirectiveContainer directiveContainer ) {
9661010 List <GraphQLAppliedDirective > directives = DirectivesUtil .toAppliedDirectives (directiveContainer );
967- if (!hasDeprecatedDirective (directives ) && isDeprecatedDirectiveAllowed ()) {
1011+ if (!hasDeprecatedDirective (directives ) && isDeprecatedDirectiveAllowed ()) {
9681012 directives = new ArrayList <>(directives );
969- String reason = getDeprecationReason (directiveContainer );
970- GraphQLAppliedDirectiveArgument arg = GraphQLAppliedDirectiveArgument .newArgument ()
971- .name ("reason" )
972- .valueProgrammatic (reason )
973- .type (GraphQLString )
974- .build ();
1013+ String reason = getDeprecationReason (directiveContainer );
1014+ GraphQLAppliedDirectiveArgument arg = GraphQLAppliedDirectiveArgument .newArgument ()
1015+ .name ("reason" )
1016+ .valueProgrammatic (reason )
1017+ .type (GraphQLString )
1018+ .build ();
9751019 GraphQLAppliedDirective directive = GraphQLAppliedDirective .newDirective ()
9761020 .name ("deprecated" )
9771021 .argument (arg )
@@ -1108,7 +1152,7 @@ private void printComments(PrintWriter out, Object graphQLType, String prefix) {
11081152 if (options .isIncludeAstDefinitionComments ()) {
11091153 String commentsText = getAstDefinitionComments (graphQLType );
11101154 if (!isNullOrEmpty (commentsText )) {
1111- List <String > lines = Arrays .asList (commentsText .split ("\n " ) );
1155+ List <String > lines = Arrays .asList (commentsText .split ("\n " ));
11121156 if (!lines .isEmpty ()) {
11131157 printMultiLineHashDescription (out , prefix , lines );
11141158 }
@@ -1183,7 +1227,7 @@ private String getAstDefinitionComments(Object commentHolder) {
11831227 }
11841228
11851229 private String comments (List <Comment > comments ) {
1186- if ( comments == null || comments .isEmpty () ) {
1230+ if (comments == null || comments .isEmpty ()) {
11871231 return null ;
11881232 }
11891233 String s = comments .stream ().map (c -> c .getContent ()).collect (joining ("\n " , "" , "\n " ));
0 commit comments