Class PossibleMappingsCalculator
- java.lang.Object
-
- graphql.schema.diffing.PossibleMappingsCalculator
-
public class PossibleMappingsCalculator extends java.lang.Object
We don't want to allow arbitrary schema changes. For example changing an Object type into a Scalar is not something we want to consider.We do this to make SchemaDiffings better understandable, but also to improve the overall runtime of the algorithm. By restricting the possible mappings the Schema diffing algo is actually able to finish in a reasonable time for real life inputs.
We restrict the algo by calculating which mappings are possible for given vertex. This is later used in
DiffImpl.calcLowerBoundMappingCost(graphql.schema.diffing.Vertex, graphql.schema.diffing.Vertex, graphql.schema.diffing.Mapping, java.util.Map<graphql.schema.diffing.Vertex, java.lang.Double>, java.util.Map<graphql.schema.diffing.Vertex, graphql.schema.diffing.Vertex>)
. While doing this we need to also ensure that there are the same amount of vertices in the same "context": for example if the source graph has 3 Objects, the target graph needs to have 3 Objects. We achieve this by adding "isolated vertices" as needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
PossibleMappingsCalculator.PossibleMappings
static class
PossibleMappingsCalculator.VertexContextSegment
-
Field Summary
Fields Modifier and Type Field Description private PossibleMappingsCalculator.PossibleMappings
possibleMappings
private SchemaDiffingRunningCheck
runningCheck
private SchemaGraph
sourceGraph
private SchemaGraph
targetGraph
private static java.util.Map<java.lang.String,java.util.List<PossibleMappingsCalculator.VertexContextSegment>>
typeContexts
-
Constructor Summary
Constructors Constructor Description PossibleMappingsCalculator(SchemaGraph sourceGraph, SchemaGraph targetGraph, SchemaDiffingRunningCheck runningCheck)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
appliedArgumentContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
appliedDirectiveContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
argumentsContexts()
private void
calcPossibleMappingImpl(java.util.Collection<Vertex> currentSourceVertices, java.util.Collection<Vertex> currentTargetVertices, java.util.List<java.lang.String> contextId, int contextIx, java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.util.Set<Vertex> usedSourceVertices, java.util.Set<Vertex> usedTargetVertices, java.lang.String typeNameForDebug)
calc for the provided contextvoid
calcPossibleMappings(java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.lang.String typeNameForDebug)
PossibleMappingsCalculator.PossibleMappings
calculate()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
directiveContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
enumContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
enumValueContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
fieldContext()
java.util.Map<Vertex,Vertex>
getFixedParentRestrictions()
private java.util.Map<Vertex,Vertex>
getFixedParentRestrictions(SchemaGraph sourceGraph, java.util.List<Vertex> fixedSourceVertices, java.util.Map<Vertex,Vertex> fixedOneToOneMappings)
This computes the initial set of parent restrictions based on the fixed portion of the mapping.java.util.Map<Vertex,Vertex>
getFixedParentRestrictionsInverse(java.util.Map<Vertex,Vertex> fixedOneToOneMappingsInverted)
java.util.Map<Vertex,Vertex>
getNonFixedParentRestrictions(SchemaGraph sourceGraph, SchemaGraph targetGraph, Mapping mapping)
This computes the initial set of parent restrictions based on the given non-fixed mapping.static boolean
hasChildrenRestrictions(Vertex vertex)
static boolean
hasParentRestrictions(Vertex vertex)
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
inputFieldContexts()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
inputObjectContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
interfaceContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
objectContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
scalarContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
schemaContext()
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment>
unionContext()
-
-
-
Field Detail
-
runningCheck
private final SchemaDiffingRunningCheck runningCheck
-
sourceGraph
private final SchemaGraph sourceGraph
-
targetGraph
private final SchemaGraph targetGraph
-
possibleMappings
private final PossibleMappingsCalculator.PossibleMappings possibleMappings
-
typeContexts
private static final java.util.Map<java.lang.String,java.util.List<PossibleMappingsCalculator.VertexContextSegment>> typeContexts
-
-
Constructor Detail
-
PossibleMappingsCalculator
public PossibleMappingsCalculator(SchemaGraph sourceGraph, SchemaGraph targetGraph, SchemaDiffingRunningCheck runningCheck)
-
-
Method Detail
-
inputFieldContexts
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> inputFieldContexts()
-
scalarContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> scalarContext()
-
inputObjectContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> inputObjectContext()
-
objectContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> objectContext()
-
enumContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> enumContext()
-
enumValueContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> enumValueContext()
-
interfaceContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> interfaceContext()
-
unionContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> unionContext()
-
directiveContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> directiveContext()
-
appliedDirectiveContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> appliedDirectiveContext()
-
appliedArgumentContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> appliedArgumentContext()
-
schemaContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> schemaContext()
-
fieldContext
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> fieldContext()
-
argumentsContexts
private static java.util.List<PossibleMappingsCalculator.VertexContextSegment> argumentsContexts()
-
calculate
public PossibleMappingsCalculator.PossibleMappings calculate()
-
calcPossibleMappings
public void calcPossibleMappings(java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.lang.String typeNameForDebug)
-
calcPossibleMappingImpl
private void calcPossibleMappingImpl(java.util.Collection<Vertex> currentSourceVertices, java.util.Collection<Vertex> currentTargetVertices, java.util.List<java.lang.String> contextId, int contextIx, java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.util.Set<Vertex> usedSourceVertices, java.util.Set<Vertex> usedTargetVertices, java.lang.String typeNameForDebug)
calc for the provided context
-
getFixedParentRestrictionsInverse
public java.util.Map<Vertex,Vertex> getFixedParentRestrictionsInverse(java.util.Map<Vertex,Vertex> fixedOneToOneMappingsInverted)
-
getFixedParentRestrictions
private java.util.Map<Vertex,Vertex> getFixedParentRestrictions(SchemaGraph sourceGraph, java.util.List<Vertex> fixedSourceVertices, java.util.Map<Vertex,Vertex> fixedOneToOneMappings)
This computes the initial set of parent restrictions based on the fixed portion of the mapping.See
Mapping
for definition of fixed vs non-fixed.If a
Vertex
is present in the outputMap
then the value is the parent the vertex MUST map to.e.g. for an output {collar: Dog} then the collar vertex must be a child of Dog in the mapping.
- Returns:
- Map where key is any vertex, and the value is the parent that vertex must map to
-
getNonFixedParentRestrictions
public java.util.Map<Vertex,Vertex> getNonFixedParentRestrictions(SchemaGraph sourceGraph, SchemaGraph targetGraph, Mapping mapping)
This computes the initial set of parent restrictions based on the given non-fixed mapping.i.e. this introduces restrictions as the
Mapping
is being built, as decisions can have knock on effects on other vertices' possible mappings.See
Mapping
for definition of fixed vs non-fixed.If a
Vertex
is present in the outputMap
then the value is the parent the vertex MUST map to.e.g. for an output {collar: Dog} then the collar vertex must be a child of Dog in the mapping.
- Parameters:
mapping
- the mapping to get non-fixed parent restrictions forsourceGraph
- the source graphtargetGraph
- the target graph- Returns:
- Map where key is any vertex, and the value is the parent that vertex must map to
-
hasParentRestrictions
public static boolean hasParentRestrictions(Vertex vertex)
-
hasChildrenRestrictions
public static boolean hasChildrenRestrictions(Vertex vertex)
-
-