7575import graphql .schema .idl .ScalarInfo ;
7676import graphql .schema .idl .TypeUtil ;
7777import graphql .schema .impl .SchemaUtil ;
78+ import org .jspecify .annotations .NullMarked ;
7879
7980import java .math .BigInteger ;
8081import java .util .ArrayList ;
9192import java .util .function .Consumer ;
9293
9394import static graphql .Assert .assertNotNull ;
95+ import static graphql .Assert .assertShouldNeverHappen ;
9496import static graphql .parser .ParserEnvironment .newParserEnvironment ;
9597import static graphql .schema .GraphQLNonNull .nonNull ;
9698import static graphql .schema .GraphQLTypeUtil .unwrapNonNull ;
105107 * into anonymized schemas and queries.
106108 */
107109@ PublicApi
110+ @ NullMarked
108111public 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
0 commit comments