Skip to content

Commit d1a4c15

Browse files
authored
Merge pull request #2136 from graphql-java/anonymizer-descriptions
Anonymizer: remove descriptions from schema
2 parents 5e61bb3 + 6fe2b25 commit d1a4c15

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

src/main/java/graphql/util/Anonymizer.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public TraversalControl visitGraphQLArgument(GraphQLArgument graphQLArgument, Tr
119119
String newName = assertNotNull(newNameMap.get(graphQLArgument));
120120
Object defaultValue = replaceDefaultValue(graphQLArgument.getDefaultValue(), defaultStringValueCounter, defaultIntValueCounter);
121121
GraphQLArgument newElement = graphQLArgument.transform(builder -> {
122-
builder.name(newName).defaultValue(defaultValue);
122+
builder.name(newName).defaultValue(defaultValue).description(null).definition(null);
123123
});
124124
return changeNode(context, newElement);
125125
}
@@ -131,7 +131,7 @@ public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType graphQLIn
131131
}
132132
String newName = assertNotNull(newNameMap.get(graphQLInterfaceType));
133133
GraphQLInterfaceType newElement = graphQLInterfaceType.transform(builder -> {
134-
builder.name(newName);
134+
builder.name(newName).description(null).definition(null);
135135
});
136136
GraphQLCodeRegistry.Builder codeRegistry = assertNotNull(context.getVarFromParents(GraphQLCodeRegistry.Builder.class));
137137
TypeResolver typeResolver = codeRegistry.getTypeResolver(graphQLInterfaceType);
@@ -146,7 +146,7 @@ public TraversalControl visitGraphQLEnumType(GraphQLEnumType graphQLEnumType, Tr
146146
}
147147
String newName = assertNotNull(newNameMap.get(graphQLEnumType));
148148
GraphQLEnumType newElement = graphQLEnumType.transform(builder -> {
149-
builder.name(newName);
149+
builder.name(newName).description(null).definition(null);
150150
});
151151
return changeNode(context, newElement);
152152
}
@@ -155,7 +155,7 @@ public TraversalControl visitGraphQLEnumType(GraphQLEnumType graphQLEnumType, Tr
155155
public TraversalControl visitGraphQLEnumValueDefinition(GraphQLEnumValueDefinition enumValueDefinition, TraverserContext<GraphQLSchemaElement> context) {
156156
String newName = assertNotNull(newNameMap.get(enumValueDefinition));
157157
GraphQLEnumValueDefinition newElement = enumValueDefinition.transform(builder -> {
158-
builder.name(newName);
158+
builder.name(newName).description(null).definition(null);
159159
});
160160
return changeNode(context, newElement);
161161
}
@@ -164,7 +164,7 @@ public TraversalControl visitGraphQLEnumValueDefinition(GraphQLEnumValueDefiniti
164164
public TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition graphQLFieldDefinition, TraverserContext<GraphQLSchemaElement> context) {
165165
String newName = assertNotNull(newNameMap.get(graphQLFieldDefinition));
166166
GraphQLFieldDefinition newElement = graphQLFieldDefinition.transform(builder -> {
167-
builder.name(newName);
167+
builder.name(newName).description(null).definition(null);
168168
});
169169
return changeNode(context, newElement);
170170
}
@@ -176,7 +176,7 @@ public TraversalControl visitGraphQLDirective(GraphQLDirective graphQLDirective,
176176
}
177177
String newName = assertNotNull(newNameMap.get(graphQLDirective));
178178
GraphQLDirective newElement = graphQLDirective.transform(builder -> {
179-
builder.name(newName);
179+
builder.name(newName).description(null).definition(null);
180180
});
181181
return changeNode(context, newElement);
182182
}
@@ -192,6 +192,8 @@ public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField gra
192192
GraphQLInputObjectField newElement = graphQLInputObjectField.transform(builder -> {
193193
builder.name(newName);
194194
builder.defaultValue(finalDefaultValue);
195+
builder.description(null);
196+
builder.definition(null);
195197
});
196198
return changeNode(context, newElement);
197199
}
@@ -203,7 +205,7 @@ public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType graph
203205
}
204206
String newName = assertNotNull(newNameMap.get(graphQLInputObjectType));
205207
GraphQLInputObjectType newElement = graphQLInputObjectType.transform(builder -> {
206-
builder.name(newName);
208+
builder.name(newName).description(null).definition(null);
207209
});
208210
return changeNode(context, newElement);
209211
}
@@ -216,7 +218,7 @@ public TraversalControl visitGraphQLObjectType(GraphQLObjectType graphQLObjectTy
216218
}
217219
String newName = assertNotNull(newNameMap.get(graphQLObjectType));
218220
GraphQLObjectType newElement = graphQLObjectType.transform(builder -> {
219-
builder.name(newName);
221+
builder.name(newName).description(null).definition(null);
220222
});
221223
return changeNode(context, newElement);
222224
}
@@ -228,7 +230,7 @@ public TraversalControl visitGraphQLScalarType(GraphQLScalarType graphQLScalarTy
228230
}
229231
String newName = assertNotNull(newNameMap.get(graphQLScalarType));
230232
GraphQLScalarType newElement = graphQLScalarType.transform(builder -> {
231-
builder.name(newName);
233+
builder.name(newName).description(null).definition(null);
232234
});
233235
return changeNode(context, newElement);
234236
}
@@ -240,7 +242,7 @@ public TraversalControl visitGraphQLUnionType(GraphQLUnionType graphQLUnionType,
240242
}
241243
String newName = assertNotNull(newNameMap.get(graphQLUnionType));
242244
GraphQLUnionType newElement = graphQLUnionType.transform(builder -> {
243-
builder.name(newName);
245+
builder.name(newName).description(null).definition(null);
244246
});
245247
GraphQLCodeRegistry.Builder codeRegistry = assertNotNull(context.getVarFromParents(GraphQLCodeRegistry.Builder.class));
246248
TypeResolver typeResolver = codeRegistry.getTypeResolver(graphQLUnionType);

src/test/groovy/graphql/util/AnonymizerTest.groovy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,41 @@ type Object2 {
483483
type Object3 {
484484
field3: [Object2]
485485
}
486+
"""
487+
}
488+
489+
def "descriptions are removed"() {
490+
def schema = TestUtil.schema("""
491+
"DOC"
492+
type Query {
493+
"DOC"
494+
query(
495+
"DOC"
496+
arg: String): Foo
497+
}
498+
"DOC"
499+
type Foo {
500+
"DOC"
501+
foo: String
502+
}
503+
504+
""")
505+
when:
506+
def result = Anonymizer.anonymizeSchema(schema)
507+
def newSchema = new SchemaPrinter(SchemaPrinter.Options.defaultOptions().includeDirectiveDefinitions(false)).print(result)
508+
509+
then:
510+
newSchema == """schema {
511+
query: Object1
512+
}
513+
514+
type Object1 {
515+
field1(argument1: String): Object2
516+
}
517+
518+
type Object2 {
519+
field2: String
520+
}
486521
"""
487522
}
488523
}

0 commit comments

Comments
 (0)