Class PossibleMappingsCalculator
- java.lang.Object
-
- graphql.schema.diffing.PossibleMappingsCalculator
-
public class PossibleMappingsCalculator extends java.lang.ObjectWe 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 classPossibleMappingsCalculator.PossibleMappingsstatic classPossibleMappingsCalculator.VertexContextSegment
-
Constructor Summary
Constructors Constructor Description PossibleMappingsCalculator(SchemaGraph sourceGraph, SchemaGraph targetGraph, graphql.schema.diffing.SchemaDiffingRunningCheck runningCheck)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcalcPossibleMappings(java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.lang.String typeNameForDebug)PossibleMappingsCalculator.PossibleMappingscalculate()java.util.Map<Vertex,Vertex>getFixedParentRestrictions()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 booleanhasChildrenRestrictions(Vertex vertex)static booleanhasParentRestrictions(Vertex vertex)
-
-
-
Constructor Detail
-
PossibleMappingsCalculator
public PossibleMappingsCalculator(SchemaGraph sourceGraph, SchemaGraph targetGraph, graphql.schema.diffing.SchemaDiffingRunningCheck runningCheck)
-
-
Method Detail
-
calculate
public PossibleMappingsCalculator.PossibleMappings calculate()
-
calcPossibleMappings
public void calcPossibleMappings(java.util.List<PossibleMappingsCalculator.VertexContextSegment> contexts, java.lang.String typeNameForDebug)
-
getFixedParentRestrictionsInverse
public java.util.Map<Vertex,Vertex> getFixedParentRestrictionsInverse(java.util.Map<Vertex,Vertex> fixedOneToOneMappingsInverted)
-
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
Mappingis being built, as decisions can have knock on effects on other vertices' possible mappings.See
Mappingfor definition of fixed vs non-fixed.If a
Vertexis present in the outputMapthen 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)
-
-