Class ProcessedSchema

java.lang.Object
no.sikt.graphql.schema.ProcessedSchema

public class ProcessedSchema extends Object
This class represents a fully processed GraphQL schema. This is Graphitron's pre-processing of the schema.
  • Constructor Details

    • ProcessedSchema

      public ProcessedSchema(graphql.schema.idl.TypeDefinitionRegistry typeRegistry)
  • Method Details

    • nodeExists

      public boolean nodeExists()
    • validate

      public void validate()
      Ensure that the definitions created in this class match database names where applicable.
    • validate

      public void validate(boolean checkTypes)
      Ensure that the definitions created in this class match database names where applicable.
    • isType

      public boolean isType(String name)
      Returns:
      Does this name belong to a valid GraphQL type in the schema?
    • isType

      public boolean isType(FieldSpecification field)
      Returns:
      Does this field type belong to a valid GraphQL type in the schema?
    • getAllValidFieldTypeNames

      public Set<String> getAllValidFieldTypeNames()
      Returns:
      Set of all possible type or scalar names that a field can have in the schema.
    • getEnums

      public Map<String,EnumDefinition> getEnums()
      Returns:
      Map of all the enums in the schema by name.
    • isEnum

      public boolean isEnum(String name)
      Returns:
      Does this name belong to an enum type in the schema?
    • isEnum

      public boolean isEnum(GenerationField field)
      Returns:
      Does this field point to an enum type in the schema?
    • isJavaMappedEnum

      public boolean isJavaMappedEnum(FieldSpecification field)
      Returns:
      Does this field point to an enum type in the schema and does it have the GenerationDirective.ENUM directive set?
    • getEnum

      public EnumDefinition getEnum(String name)
      Returns:
      Get an enum with this name.
    • getEnum

      public EnumDefinition getEnum(FieldSpecification field)
      Returns:
      Get the enum that this field points to.
    • getInterfaces

      public Map<String,InterfaceDefinition> getInterfaces()
      Returns:
      Map of all the interfaces in the schema by name.
    • isInterface

      public boolean isInterface(String name)
      Returns:
      Does this name belong to an interface type in the schema?
    • isInterface

      public boolean isInterface(GenerationField field)
      Returns:
      Does this field point to an interface type in the schema?
    • isMultiTableInterface

      public boolean isMultiTableInterface(GenerationField field)
      Returns:
      Does this field return a multi-table interface type in the schema?
    • isMultiTableInterface

      public boolean isMultiTableInterface(String name)
      Returns:
      Does this name belong to a multi-table interface type in the schema?
    • isSingleTableInterface

      public boolean isSingleTableInterface(GenerationField field)
      Returns:
      Does this field return a single table interface type in the schema?
    • isSingleTableInterface

      public boolean isSingleTableInterface(String name)
      Returns:
      Does this name belong to a single table interface type in the schema?
    • isMultiTableField

      public boolean isMultiTableField(GenerationField field)
      Returns:
      Does this field return rows from multiple tables?
    • getInterface

      public InterfaceDefinition getInterface(String name)
      Returns:
      Get an interface with this name.
    • getInterface

      public InterfaceDefinition getInterface(FieldSpecification field)
      Returns:
      Get the interface that this field points to.
    • getImplementationsForInterface

      public List<ObjectDefinition> getImplementationsForInterface(String interfaceName)
      Returns:
      Get the implementations for an interface given its name
    • getImplementationsForInterface

      public List<ObjectDefinition> getImplementationsForInterface(InterfaceDefinition interfaceDefinition)
      Returns:
      Get the implementations for an interface
    • getUnionSubTypes

      public List<ObjectDefinition> getUnionSubTypes(String objectName)
      Returns:
      Get the ObjectDefinition for each Type in a Union given its name
    • getTypesFromInterfaceOrUnion

      public Optional<List<ObjectDefinition>> getTypesFromInterfaceOrUnion(String name)
      Returns the ObjectDefinition for each Type in a union given that the name supplied is a union. Otherwise, return the ObjectDefinition for all types that implements the given interface.
    • getTypesFromInterfaceOrUnion

      public Optional<List<ObjectDefinition>> getTypesFromInterfaceOrUnion(RecordObjectSpecification<?> definition)
      Returns the ObjectDefinition for each type implementing an interface or union given its definition
    • getObjects

      public Map<String,ObjectDefinition> getObjects()
      Returns:
      Map of all the objects in the schema by name.
    • getUnreferencedObjects

      public List<ObjectDefinition> getUnreferencedObjects()
      Returns:
      List of all the objects in the schema that are not referenced by an object field.
    • getEntities

      public Map<String,ObjectDefinition> getEntities()
      Returns:
      Map of all the types by name that have the federation directive @key set.
    • isEntity

      public boolean isEntity(String typeName)
    • getScalarTypes

      public Set<String> getScalarTypes()
      Returns:
      Set of all the scalar types in the schema.
    • isObject

      public boolean isObject(String name)
      Returns:
      Does this name belong to an object type in the schema?
    • isObject

      public boolean isObject(FieldSpecification field)
      Returns:
      Does this field point to an object type in the schema?
    • getObject

      public ObjectDefinition getObject(String name)
      Returns:
      Get an object with this name.
    • isNodeType

      public boolean isNodeType(String name)
    • getNodeType

      public ObjectDefinition getNodeType(String name)
    • getNodeTypesWithTable

      public List<ObjectDefinition> getNodeTypesWithTable(JOOQMapping table)
    • getObject

      public ObjectDefinition getObject(FieldSpecification field)
      Returns:
      Get the object that this field points to.
    • getObjectOrConnectionNode

      public ObjectDefinition getObjectOrConnectionNode(String name)
      Returns:
      Get an object or connection node with this name.
    • getObjectOrConnectionNode

      public ObjectDefinition getObjectOrConnectionNode(GenerationField field)
      Returns:
      Get the object or connection node that this field points to.
    • hasTableObject

      public boolean hasTableObject(String name)
      Returns:
      Does this name belong to an object type or connection node in the schema that is connected to a database table?
    • hasTableObject

      public boolean hasTableObject(FieldSpecification field)
      Returns:
      Does this field point to an object type or connection node in the schema that is connected to a database table?
    • implementsNode

      public boolean implementsNode(String name)
      Returns:
      Does this name point to an object type in the schema which implements the Node interface?
    • implementsNode

      public boolean implementsNode(FieldSpecification field)
      Returns:
      Does this field point to an object type in the schema which implements the Node interface?
    • implementsInterface

      public boolean implementsInterface(String name, String interfaceName)
      Returns:
      Does this name point to an object type in the schema which implements the interface?
    • implementsInterface

      public boolean implementsInterface(FieldSpecification field, String interfaceName)
      Returns:
      Does this field point to an object type in the schema which implements the interface?
    • isConnectionObject

      public boolean isConnectionObject(String name)
      Returns:
      Does this name belong to a connection object type in the schema?
    • isConnectionObject

      public boolean isConnectionObject(FieldSpecification field)
      Returns:
      Does this field point to a connection object type in the schema?
    • getConnectionObject

      public ConnectionObjectDefinition getConnectionObject(String name)
      Returns:
      Get a connection object with this name.
    • getConnectionObject

      public ConnectionObjectDefinition getConnectionObject(GenerationField field)
      Returns:
      Get the connection object that this field points to.
    • isEdgeObject

      public boolean isEdgeObject(String name)
      Returns:
      Does this name belong to an edge object type in the schema?
    • getExceptions

      public Map<String,ExceptionDefinition> getExceptions()
      Returns:
      Map of all the exceptions in the schema by name.
    • isException

      public boolean isException(String name)
      Returns:
      Does this name belong to an exception type in the schema?
    • getException

      public ExceptionDefinition getException(String name)
      Returns:
      Get an exception with this name.
    • getInputTypes

      public Map<String,InputDefinition> getInputTypes()
      Returns:
      Map of all the input type objects in the schema by name.
    • isInputType

      public boolean isInputType(String name)
      Returns:
      Does this name belong to an input type in the schema?
    • isInputType

      public boolean isInputType(FieldSpecification field)
      Returns:
      Does this field point to an input type in the schema?
    • hasJOOQRecord

      public boolean hasJOOQRecord(String name)
      Returns:
      Does this name point to a type that has a table set?
    • hasJOOQRecord

      public boolean hasJOOQRecord(GenerationField field)
      Returns:
      Does this field point to a type that has a table set?
    • hasInputJOOQRecord

      public boolean hasInputJOOQRecord(GenerationField field)
      Returns:
      Does this field point to an input type with a table set in the schema?
    • hasJavaRecord

      public boolean hasJavaRecord(String typeName)
      Returns:
      Does this type name point to a type with a Java record?
    • hasJavaRecord

      public boolean hasJavaRecord(GenerationField field)
      Returns:
      Does this field point to a type with a Java record set in the schema?
    • hasRecord

      public boolean hasRecord(GenerationField field)
      Returns:
      Does this field point to an input type with a record set in the schema?
    • hasRecord

      public boolean hasRecord(String typeName)
    • isOrderedMultiKeyQuery

      public boolean isOrderedMultiKeyQuery(GenerationField field)
      Returns:
      Is this an ordered multi-key query?
    • getInputType

      public InputDefinition getInputType(String name)
      Returns:
      Get an input type with this name.
    • getInputType

      public InputDefinition getInputType(GenerationField field)
      Returns:
      Get the input type that this field points to.
    • isUnion

      public boolean isUnion(String name)
      Returns:
      Does this name belong to a union type in the schema?
    • isUnion

      public boolean isUnion(FieldSpecification field)
      Returns:
      Does this field belong to a union type in the schema?
    • isExceptionUnion

      public boolean isExceptionUnion(String name)
      Returns:
      Does this name belong to a union type containing only error types?
    • isExceptionOrExceptionUnion

      public boolean isExceptionOrExceptionUnion(String name)
      Returns:
      Does this name belong to an exception type or a union type containing only error types?
    • isExceptionOrExceptionUnion

      public boolean isExceptionOrExceptionUnion(FieldSpecification field)
      Returns:
      Does this field belong to an exception type or a union type containing only error types?
    • getUnion

      public UnionDefinition getUnion(String name)
      Returns:
      Get a union type with this name.
    • getUnion

      public UnionDefinition getUnion(GenerationField field)
      Returns:
      Get a union type that this field points to.
    • getUnions

      public Map<String,UnionDefinition> getUnions()
      Returns:
      Get all union types keyed by name.
    • isScalar

      public boolean isScalar(String name)
      Returns:
      Does this name belong to a scalar in the schema?
    • isScalar

      public boolean isScalar(GenerationField field)
      Returns:
      Is this field a scalar in the schema?
    • getQueryType

      public ObjectDefinition getQueryType()
      Returns:
      The Query type.
    • getMutationType

      public ObjectDefinition getMutationType()
      Returns:
      The Mutation type, if it exists.
    • getSchemaType

      public SchemaDefinition getSchemaType()
      Returns:
      The root schema type, if it exists.
    • isRecordType

      public boolean isRecordType(String name)
      Returns:
      Does this name point to a type that may have a record set?
    • isRecordType

      public boolean isRecordType(FieldSpecification field)
      Returns:
      Does this field point to a type that may have a record set?
    • getRecordType

      public RecordObjectSpecification<?> getRecordType(String name)
      Returns:
      Find the type this field refers to.
    • getRecordType

      public RecordObjectSpecification<?> getRecordType(GenerationField field)
      Returns:
      Find the type this field refers to.
    • federationEntitiesExist

      public boolean federationEntitiesExist()
      Returns:
      Does this schema import federation and have the _entities field?
    • getRecordTypes

      public Map<String,RecordObjectSpecification<? extends GenerationField>> getRecordTypes()
      Returns:
      All types which could potentially have tables.
    • isNodeIdField

      public boolean isNodeIdField(GenerationField field)
      Returns:
      Whether a field is a node ID field using NodeIdStrategy
    • getNodeTypeForNodeIdField

      public Optional<ObjectDefinition> getNodeTypeForNodeIdField(GenerationField field)
      Parameters:
      field - the GenerationField to resolve the node type for
      Returns:
      the corresponding RecordObjectSpecification, or null if not found
    • getNodeTypeForNodeIdFieldOrThrow

      public ObjectDefinition getNodeTypeForNodeIdFieldOrThrow(GenerationField field)
      Finds node type for a node ID field. If not found an error is thrown.
      Parameters:
      field - The GenerationField to resolve the node type for. The field must be a node ID field.
      Returns:
      the corresponding RecordObjectSpecification
    • getNodeConfigurationForNodeIdFieldOrThrow

      public NodeConfiguration getNodeConfigurationForNodeIdFieldOrThrow(GenerationField field)
      Finds node type for a node ID field. If not found an error is thrown.
      Parameters:
      field - The GenerationField to resolve the node type for. The field must be a node ID field.
      Returns:
      the corresponding RecordObjectSpecification
    • getNodeConfigurationForTypeOrThrow

      public NodeConfiguration getNodeConfigurationForTypeOrThrow(String typeName)
      Returns the NodeConfiguration for the given type name, or throws if the @node configuration is missing.
      Parameters:
      typeName - the name of a node type in the schema
      Returns:
      the node configuration for the type
    • getNodeConfigurationForTypeOrThrow

      public NodeConfiguration getNodeConfigurationForTypeOrThrow(RecordObjectSpecification<?> object)
      Returns the NodeConfiguration for the given object, or throws if the @node configuration is missing.
      Parameters:
      object - the record object to retrieve the node configuration from
      Returns:
      the node configuration for the object
    • isFederationService

      public boolean isFederationService(GenerationField target)
      Returns:
      Is this field the federation _service field?
    • getResolvedOrderInput

      public ProcessedSchema.ResolvedOrderInput getResolvedOrderInput(InputField orderInputField)
      Returns:
      The resolved order input structure for the given orderInputField, with the enum definition and the actual fields for the orderBy enum and direction. Assumes the input type structure has been validated by ProcessedDefinitionsValidator.
    • getPreviousTableObjectForObject

      public RecordObjectSpecification<?> getPreviousTableObjectForObject(RecordObjectSpecification<?> object)
      Returns:
      The closest table on or above this object. Assumes only one table can be associated with the object.
    • getPreviousTableObjectForField

      public RecordObjectSpecification<?> getPreviousTableObjectForField(GenerationField field)
      Returns:
      The closest table on or above this field. Assumes only one table can be associated with the object.
    • hasTableObjectForObject

      public boolean hasTableObjectForObject(RecordObjectSpecification<?> object)
      Returns:
      Returns whether the object has a table on or above it.
    • isObjectWithPreviousTableObject

      public boolean isObjectWithPreviousTableObject(String name)
    • isObjectOrConnectionNodeWithPreviousTableObject

      public boolean isObjectOrConnectionNodeWithPreviousTableObject(String name)
    • isReferenceResolverField

      public boolean isReferenceResolverField(ObjectField field)
    • invokesSubquery

      public boolean invokesSubquery(GenerationField field, JOOQMapping currentTable)
      Determines whether the field requires a correlated subquery in the generated database query.

      A correlated subquery is needed when resolving the field requires joining to a different table or fetching data that cannot be selected directly from the current table context.

      Returns true when any of the following conditions are met:

      • The field has explicit references via @references directive
      • The field's type maps to a different table than the current table (implicit reference)
      • The field is a node ID reference field
      • The field is a root query field with iterable-wrapped output and no parent table context

      Parameters:
      field - the field to check for subquery requirement
      currentTable - the table context from which the field is being resolved
      Returns:
      true if resolving this field requires a correlated subquery, false otherwise
    • returnsList

      public boolean returnsList(ObjectField field)
    • findInputTables

      public List<JOOQMapping> findInputTables(GenerationField field)
      Simple method that tries to find a table reference in the input records. This is not very robust, but we need this to not break existing things.
      Returns:
      Table mapping for this context based on input records, if any exists.
    • inferDataTargetForMutation

      public Optional<ObjectField> inferDataTargetForMutation(ObjectField initialTarget)
      Finds the target field which the returned data from mutation should be outputted. In the case of the mutation field being a wrapper type, this method will find the correct field inside the wrapper type which will contain data. This method assumes there is maximum one level of nesting.
      Parameters:
      initialTarget - The mutation field
      Returns:
      The field which should contain the return data
    • isDeleteMutationWithReturning

      public boolean isDeleteMutationWithReturning(ObjectField field)
    • isInsertMutationWithReturning

      public boolean isInsertMutationWithReturning(ObjectField field)
    • nextTypeTableExists

      public boolean nextTypeTableExists(GenerationField field, Set<String> seen)
      Simple method that tries to find a table reference the field's type.
      Returns:
      Table mapping for this context based on the contents of the field's type records, if any exists.
    • getAllErrors

      @NotNull public @NotNull List<ObjectField> getAllErrors(String typeName)
      Returns:
      List of all error types this type contains.
    • getErrorTypeDefinition

      @NotNull public @NotNull AbstractObjectDefinition<?,?> getErrorTypeDefinition(String name)
      Returns:
      The error type or union of error types with this name if it exists.
    • getExceptionDefinitions

      @NotNull public @NotNull List<ExceptionDefinition> getExceptionDefinitions(String name)
      Returns:
      List of exception definitions that exists for this type name. If it is not a union, the list will only have one element.
    • getAllContextFields

      public Map<String,no.sikt.graphitron.javapoet.TypeName> getAllContextFields(GenerationField field)
    • getTransformableFields

      public List<GenerationField> getTransformableFields()
      Returns:
      List of fields in the schema that may be used to generate transforms.
    • isFederationImported

      public boolean isFederationImported()