Class ShallowTypeRefCollector

java.lang.Object
graphql.schema.ShallowTypeRefCollector

@NullMarked public class ShallowTypeRefCollector extends Object
Collects type-refs found in type- and directive-definitions for later replacement with actual types. This class performs shallow scans (no recursive traversal from one type-def to another) and collects replacement targets that need their type references resolved. Also tracks interface-to-implementation relationships.
  • Constructor Details

    • ShallowTypeRefCollector

      public ShallowTypeRefCollector()
  • Method Details

    • handleTypeDef

      public void handleTypeDef(GraphQLNamedType type)
      Scan a type definition for type references. Called on GraphQL{Object|Input|Scalar|Union|etc}Type - NOT on wrappers or type-refs.
      Parameters:
      type - the named type to scan
    • scanAppliedDirectives

      public void scanAppliedDirectives(List<GraphQLAppliedDirective> appliedDirectives)
      Scan applied directives for type references in their arguments.
      Parameters:
      appliedDirectives - the applied directives to scan
    • handleDirective

      public void handleDirective(GraphQLDirective directive)
      Scan a directive definition for type references in its arguments.
      Parameters:
      directive - the directive definition to scan
    • replaceTypes

      public void replaceTypes(Map<String,GraphQLNamedType> typeMap)
      Replace all collected type references with actual types from typeMap. After this call, no GraphQLTypeReference should remain in the schema.

      Important: This method mutates the type objects that were scanned via handleTypeDef(GraphQLNamedType) and handleDirective(GraphQLDirective). The same type instances cannot be reused to build another schema after this method has been called. If you need to build multiple schemas with the same types, you must create new type instances for each schema.

      Parameters:
      typeMap - the map of type names to actual types
      Throws:
      AssertException - if a referenced type is not found in typeMap
    • getInterfaceNameToObjectTypeNames

      public com.google.common.collect.ImmutableMap<String,com.google.common.collect.ImmutableList<String>> getInterfaceNameToObjectTypeNames()
      Returns an immutable map of interface names to sorted lists of implementing object type names. The object type names are maintained in sorted order as they're added.
      Returns:
      immutable map from interface name to list of object type names