Skip to content

Commit 23afaea

Browse files
committed
Annotate Anonymizer
1 parent 71ef680 commit 23afaea

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import graphql.schema.idl.ScalarInfo;
7676
import graphql.schema.idl.TypeUtil;
7777
import graphql.schema.impl.SchemaUtil;
78+
import org.jspecify.annotations.NullMarked;
7879

7980
import java.math.BigInteger;
8081
import java.util.ArrayList;
@@ -91,6 +92,7 @@
9192
import java.util.function.Consumer;
9293

9394
import static graphql.Assert.assertNotNull;
95+
import static graphql.Assert.assertShouldNeverHappen;
9496
import static graphql.parser.ParserEnvironment.newParserEnvironment;
9597
import static graphql.schema.GraphQLNonNull.nonNull;
9698
import static graphql.schema.GraphQLTypeUtil.unwrapNonNull;
@@ -105,6 +107,7 @@
105107
* into anonymized schemas and queries.
106108
*/
107109
@PublicApi
110+
@NullMarked
108111
public class Anonymizer {
109112

110113
public static class AnonymizeResult {
@@ -393,7 +396,7 @@ private static Value replaceValue(Value valueLiteral, GraphQLInputType argType,
393396
} else if (valueLiteral instanceof EnumValue) {
394397
GraphQLEnumType enumType = unwrapNonNullAs(argType);
395398
GraphQLEnumValueDefinition enumValueDefinition = enumType.getValue(((EnumValue) valueLiteral).getName());
396-
String newName = newNameMap.get(enumValueDefinition);
399+
String newName = assertNotNull(newNameMap.get(enumValueDefinition), "No new name found for enum value %s", ((EnumValue) valueLiteral).getName());
397400
return new EnumValue(newName);
398401
} else if (valueLiteral instanceof ObjectValue) {
399402
GraphQLInputObjectType inputObjectType = unwrapNonNullAs(argType);
@@ -659,7 +662,7 @@ private static void getSameFieldsImpl(String fieldName,
659662
alreadyChecked.add(curObjectOrInterface);
660663

661664
// "up": get all Interfaces
662-
GraphQLImplementingType type = (GraphQLImplementingType) schema.getType(curObjectOrInterface);
665+
GraphQLImplementingType type = assertNotNull((GraphQLImplementingType) schema.getType(curObjectOrInterface), "No type found for %s", curObjectOrInterface);
663666
List<GraphQLNamedOutputType> interfaces = type.getInterfaces();
664667
getMatchingFieldDefinitions(fieldName, interfaces, result);
665668
for (GraphQLNamedOutputType interfaze : interfaces) {
@@ -905,15 +908,13 @@ private static GraphQLType fromTypeToGraphQLType(Type type, GraphQLSchema schema
905908
if (type instanceof TypeName) {
906909
String typeName = ((TypeName) type).getName();
907910
GraphQLType graphQLType = schema.getType(typeName);
908-
graphql.Assert.assertNotNull(graphQLType, "Schema must contain type %s", typeName);
909-
return graphQLType;
911+
return assertNotNull(graphQLType, "Schema must contain type %s", typeName);
910912
} else if (type instanceof NonNullType) {
911913
return nonNull(fromTypeToGraphQLType(TypeUtil.unwrapOne(type), schema));
912914
} else if (type instanceof ListType) {
913915
return GraphQLList.list(fromTypeToGraphQLType(TypeUtil.unwrapOne(type), schema));
914916
} else {
915-
graphql.Assert.assertShouldNeverHappen();
916-
return null;
917+
return assertShouldNeverHappen();
917918
}
918919
}
919920

@@ -926,8 +927,7 @@ private static Type replaceTypeName(Type type, String newName) {
926927
} else if (type instanceof NonNullType) {
927928
return NonNullType.newNonNullType(replaceTypeName(((NonNullType) type).getType(), newName)).build();
928929
} else {
929-
graphql.Assert.assertShouldNeverHappen();
930-
return null;
930+
return assertShouldNeverHappen();
931931
}
932932
}
933933

src/test/groovy/graphql/archunit/JSpecifyAnnotationsCheck.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ class JSpecifyAnnotationsCheck extends Specification {
263263
"graphql.schema.visibility.GraphqlFieldVisibility",
264264
"graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility",
265265
"graphql.schema.visitor.GraphQLSchemaTraversalControl",
266-
"graphql.util.Anonymizer",
267266
"graphql.util.CyclicSchemaAnalyzer",
268267
"graphql.util.NodeAdapter",
269268
"graphql.util.NodeLocation",

0 commit comments

Comments
 (0)