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 Set<ObjectDefinition> getImplementationsForInterface(String interfaceName)
      Returns:
      Get the implementations for an interface given its name
    • getImplementationsForInterface

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

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

      public Set<ObjectDefinition> getTypesFromInterfaceOrUnion(String name)
    • getTypesFromInterfaceOrUnion

      public Set<ObjectDefinition> getTypesFromInterfaceOrUnion(InterfaceDefinition interfaceDefinition)
    • getTypesFromInterfaceOrUnion

      public Set<ObjectDefinition> getTypesFromInterfaceOrUnion(UnionDefinition unionDefinition)
    • 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.
    • 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?
    • 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.
    • hasEntitiesField

      public boolean hasEntitiesField()
      Returns:
      Does this schema use the _entities field?
    • getEntitiesField

      public ObjectField getEntitiesField()
      Returns:
      The _entities field in the Query type, if it exists.
    • 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
    • isNodeIdReferenceField

      public boolean isNodeIdReferenceField(GenerationField field)
    • isNodeIdForNodeTypeWithSameTable

      public boolean isNodeIdForNodeTypeWithSameTable(GenerationField field)
      Is this a node ID field in a non-node type that shares the same table with another node type?
      Returns:
      Whether this is a field creating a node ID for another node type from the current table
    • getNodeTypeForNodeIdField

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

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

      public OrderByEnumDefinition getOrderByFieldEnum(InputField orderInputField)
      Returns:
      The enum definition representing the OrderByField of the given orderInputField
    • 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.
    • 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)
    • 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.
    • 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.