• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ekryd / sortgraphql / 2150

08 Apr 2024 05:09PM CUT coverage: 98.082%. Remained the same
2150

push

circleci

web-flow
Update dependency commons-io:commons-io to v2.16.1

818 of 834 relevant lines covered (98.08%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/sorter/src/main/java/sortgraphql/sort/OptionsBuilder.java
1
package sortgraphql.sort;
2

3
import graphql.language.AbstractDescribedNode;
4
import graphql.schema.*;
5
import java.util.Comparator;
6
import java.util.function.Predicate;
7

8
public class OptionsBuilder {
9
  private final DefaultGraphqlTypeComparatorRegistry.Builder comparatorRegistryBuilder =
1✔
10
      DefaultGraphqlTypeComparatorRegistry.newComparators();
1✔
11
  private boolean includeIntrospectionTypes;
12
  private boolean includeScalars;
13
  private boolean includeSchemaDefinition;
14
  private boolean includeDirectiveDefinitions;
15
  private boolean includeDefinedDirectiveDefinitions;
16
  private boolean descriptionsAsHashComments;
17
  private Predicate<GraphQLDirective> includeDirective = directive -> true;
1✔
18
  private Predicate<GraphQLSchemaElement> includeSchemaElement = element -> true;
1✔
19
  private Predicate<AbstractDescribedNode<?>> nodeDescriptionFilter = node -> true;
1✔
20

21
  private OptionsBuilder() {}
1✔
22

23
  public static OptionsBuilder defaultOptions() {
24
    return new OptionsBuilder()
1✔
25
        .setIncludeIntrospectionTypes(false)
1✔
26
        .setIncludeScalars(true)
1✔
27
        .setIncludeSchemaDefinition(false)
1✔
28
        .setIncludeDirectiveDefinitions(true)
1✔
29
        .setIncludeDefinedDirectiveDefinitions(false)
1✔
30
        .setDescriptionsAsHashComments(false);
1✔
31
  }
32

33
  /** This will allow you to include introspection types that are contained in a schema */
34
  public OptionsBuilder setIncludeIntrospectionTypes(boolean includeIntrospectionTypes) {
35
    this.includeIntrospectionTypes = includeIntrospectionTypes;
1✔
36
    return this;
1✔
37
  }
38

39
  /** This will allow you to include scalar types that are contained in a schema */
40
  public OptionsBuilder setIncludeScalars(boolean includeScalars) {
41
    this.includeScalars = includeScalars;
1✔
42
    return this;
1✔
43
  }
44

45
  /**
46
   * This will force the printing of the graphql schema definition even if the query, mutation,
47
   * and/or subscription types use the default names. Some graphql parsers require this information
48
   * even if the schema uses the default type names. The schema definition will always be printed if
49
   * any of the query, mutation, or subscription types do not use the default names.
50
   */
51
  public OptionsBuilder setIncludeSchemaDefinition(boolean includeSchemaDefinition) {
52
    this.includeSchemaDefinition = includeSchemaDefinition;
1✔
53
    return this;
1✔
54
  }
55

56
  /**
57
   * This flag controls whether schema printer will include directive definitions at the top of the
58
   * schema, but does not remove them from the field or type usage.
59
   *
60
   * <p>In some schema definitions, like Apollo Federation, the schema should be printed without the
61
   * directive definitions. This simplified schema is returned by a GraphQL query to other services,
62
   * in a format that is different that the introspection query.
63
   *
64
   * <p>On by default.
65
   */
66
  public OptionsBuilder setIncludeDirectiveDefinitions(boolean includeDirectiveDefinitions) {
67
    this.includeDirectiveDefinitions = includeDirectiveDefinitions;
1✔
68
    return this;
1✔
69
  }
70

71
  /**
72
   * This flag controls whether schema printer will include non-standard directive definitions at
73
   * the top of the schema, but does not remove them from the field or type usage.
74
   *
75
   * <p>Off by default.
76
   */
77
  public OptionsBuilder setIncludeDefinedDirectiveDefinitions(
78
      boolean includeDefinedDirectiveDefinitions) {
79
    this.includeDefinedDirectiveDefinitions = includeDefinedDirectiveDefinitions;
1✔
80
    return this;
1✔
81
  }
82

83
  /**
84
   * Descriptions are defined as preceding string literals, however an older legacy versions of SDL
85
   * supported preceding '#' comments as descriptions. Set this to true to enable this deprecated
86
   * behavior. This option is provided to ease adoption and may be removed in future versions.
87
   */
88
  public OptionsBuilder setDescriptionsAsHashComments(boolean descriptionsAsHashComments) {
89
    this.descriptionsAsHashComments = descriptionsAsHashComments;
1✔
90
    return this;
1✔
91
  }
92

93
  /**
94
   * This is a Predicate that decides whether a directive element is printed.
95
   *
96
   * @param includeDirective the predicate to decide of a directive is printed
97
   * @return new instance of options
98
   */
99
  public OptionsBuilder setIncludeDirective(Predicate<GraphQLDirective> includeDirective) {
100
    this.includeDirective = includeDirective;
×
101
    return this;
×
102
  }
103

104
  /**
105
   * This is a general purpose Predicate that decides whether a schema element is printed ever.
106
   *
107
   * @param includeSchemaElement the predicate to decide of a schema is printed
108
   * @return new instance of options
109
   */
110
  public OptionsBuilder setIncludeSchemaElement(
111
      Predicate<GraphQLSchemaElement> includeSchemaElement) {
112
    this.includeSchemaElement = includeSchemaElement;
×
113
    return this;
×
114
  }
115

116
  /**
117
   * The comparator registry controls the printing order for registered {@code GraphQLType}s.
118
   *
119
   * <p>The default is to sort elements by name, but you can put in your own code to decide on the
120
   * field order
121
   */
122
  public <T extends GraphQLType> OptionsBuilder addComparatorToRegistry(
123
      GraphqlTypeComparatorEnvironment environment, Comparator<? super T> comparator) {
124

125
    @SuppressWarnings("unchecked")
126
    var clazz = (Class<T>) GraphQLType.class;
1✔
127
    this.comparatorRegistryBuilder.addComparator(environment, clazz, comparator);
1✔
128
    return this;
1✔
129
  }
130

131
  /** This is a general purpose Predicate that decides whether any type of node is printed ever. */
132
  public OptionsBuilder setNodeDescriptionFilter(
133
      Predicate<AbstractDescribedNode<?>> nodeDescriptionFilter) {
134
    this.nodeDescriptionFilter = nodeDescriptionFilter;
1✔
135
    return this;
1✔
136
  }
137

138
  public Options build() {
139
    return new Options(
1✔
140
        includeIntrospectionTypes,
141
        includeScalars,
142
        includeSchemaDefinition,
143
        includeDirectiveDefinitions,
144
        includeDefinedDirectiveDefinitions,
145
        descriptionsAsHashComments,
146
        includeDirective,
147
        includeSchemaElement,
148
        comparatorRegistryBuilder.build(),
1✔
149
        nodeDescriptionFilter);
150
  }
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc