private void MergeNextType( ISchemaMergeContext context, List <IDirectiveTypeInfo> notMerged) { IDirectiveTypeInfo left = notMerged[0]; var readyToMerge = new List <IDirectiveTypeInfo>(); readyToMerge.Add(left); for (int i = 1; i < notMerged.Count; i++) { if (CanBeMerged(left.Definition, notMerged[i].Definition)) { readyToMerge.Add(notMerged[i]); } } NameString name = readyToMerge[0].Definition.Name.Value; if (context.ContainsDirective(name)) { throw new InvalidOperationException($"Unable to merge {name}, directive with this name already exists."); } MergeTypes(context, readyToMerge, name); notMerged.RemoveAll(readyToMerge.Contains); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <ITypeInfo> types) { if (types.OfType <UnionTypeInfo>().Any()) { var notMerged = types.OfType <UnionTypeInfo>().ToList(); bool hasLeftovers = types.Count > notMerged.Count; for (int i = 0; i < notMerged.Count; i++) { context.AddType(notMerged[i].Definition.Rename( TypeMergeHelpers.CreateName(context, notMerged[i]), notMerged[i].Schema.Name)); } if (hasLeftovers) { _next.Invoke(context, types.NotOfType <UnionTypeInfo>()); } } else { _next.Invoke(context, types); } }
private void MergeNextType( ISchemaMergeContext context, List <T> notMerged) { T left = notMerged[0]; var readyToMerge = new List <T>(); readyToMerge.Add(left); for (int i = 1; i < notMerged.Count; i++) { if (CanBeMerged(left, notMerged[i])) { readyToMerge.Add(notMerged[i]); } } NameString newTypeName = TypeMergeHelpers.CreateName <T>( context, readyToMerge); MergeTypes(context, readyToMerge, newTypeName); notMerged.RemoveAll(readyToMerge.Contains); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <IDirectiveTypeInfo> directives) { context.AddDirective( directives.First(t => t.Definition.Arguments.Any()).Definition); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <IDirectiveTypeInfo> types) { var notMerged = types.ToList(); while (notMerged.Count > 0) { MergeNextType(context, notMerged); } }
public void Merge( ISchemaMergeContext context, IReadOnlyList <ITypeInfo> types) { IReadOnlyList <ITypeInfo> unhandled = types.OfType <ScalarTypeInfo>().Any() ? types.NotOfType <ScalarTypeInfo>() : types; _next.Invoke(context, unhandled); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <ITypeInfo> types) { var typeInfos = types.OfType <ObjectTypeInfo>().ToArray(); var fields = typeInfos[0].Definition.Fields.ToList(); fields.AddRange(typeInfos[1].Definition.Fields); context.AddType( typeInfos[0].Definition.WithFields(fields)); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <HotChocolate.Stitching.Merge.ITypeInfo> types) { if (types.OfType <ITypeInfo <ScalarTypeDefinitionNode> >().Any()) { ITypeInfo <ScalarTypeDefinitionNode> scalar = types.OfType <ITypeInfo <ScalarTypeDefinitionNode> >().FirstOrDefault(); context.AddType(scalar.Definition); return; } _next(context, types); }
private void MergeTypes( ISchemaMergeContext context, ISet <string> typeNames, IReadOnlyCollection <ISchemaInfo> schemas, MergeTypeRuleDelegate merge) { var types = new List <ITypeInfo>(); foreach (string typeName in typeNames) { SetTypes(typeName, schemas, types); merge(context, types); } }
private void MergeDirectives( ISchemaMergeContext context, ISet <string> typeNames, IEnumerable <ISchemaInfo> schemas, MergeDirectiveRuleDelegate merge) { var directives = new List <IDirectiveTypeInfo>(); foreach (string typeName in typeNames) { SetDirectives(typeName, schemas, directives); merge(context, directives); } }
protected override void MergeTypes( ISchemaMergeContext context, IReadOnlyList <InputObjectTypeInfo> types, NameString newTypeName) { List <InputObjectTypeDefinitionNode> definitions = types .Select(t => t.Definition) .ToList(); InputObjectTypeDefinitionNode definition = definitions[0].Rename( newTypeName, types.Select(t => t.Schema.Name)); context.AddType(definition); }
protected void MergeTypes( ISchemaMergeContext context, IReadOnlyList <IDirectiveTypeInfo> types, NameString newTypeName) { var definitions = types .Select(t => t.Definition) .ToList(); DirectiveDefinitionNode definition = definitions[0].Rename( newTypeName, types.Select(t => t.Schema.Name)); context.AddDirective(definition); }
private static void MergeType( ISchemaMergeContext context, IReadOnlyList <EnumTypeInfo> types) { var definition = types[0].Definition; EnumTypeDefinitionNode descriptionDef = types.Select(t => t.Definition) .FirstOrDefault(t => t.Description != null); if (descriptionDef != null) { definition = definition.WithDescription( descriptionDef.Description); } context.AddType(definition.Rename( TypeMergeHelpers.CreateName(context, types), types.Select(t => t.Schema.Name))); }
protected override void MergeTypes( ISchemaMergeContext context, IReadOnlyList <ObjectTypeInfo> types, NameString newTypeName) { List <ObjectTypeDefinitionNode> definitions = types .Select(t => t.Definition) .ToList(); // ? : how do we handle the interfaces correctly var interfaces = new HashSet <string>( definitions.SelectMany(d => d.Interfaces.Select(t => t.Name.Value))); ObjectTypeDefinitionNode definition = definitions[0] .WithInterfaces(interfaces.Select(t => new NamedTypeNode(new NameNode(t))).ToList()) .Rename(newTypeName, types.Select(t => t.Schema.Name)); context.AddType(definition); }
private static void MergeRootType( ISchemaMergeContext context, OperationType operation, IEnumerable <ISchemaInfo> schemas, MergeTypeRuleDelegate merge) { var types = new List <TypeInfo>(); foreach (ISchemaInfo schema in schemas) { ObjectTypeDefinitionNode rootType = schema.GetRootType(operation); if (rootType is not null) { types.Add(new ObjectTypeInfo(rootType, schema)); } } if (types.Count > 0) { merge(context, types); } }
public void Merge( ISchemaMergeContext context, IReadOnlyList <ITypeInfo> types) { if (types.Count > 0) { if (types[0].IsRootType) { var names = new HashSet <string>(); var fields = new List <FieldDefinitionNode>(); foreach (ObjectTypeInfo type in types.OfType <ObjectTypeInfo>()) { IntegrateFields(type.Definition, type, names, fields); } if (types[0].Schema.TryGetOperationType( (ObjectTypeDefinitionNode)types[0].Definition, out OperationType operationType)) { var mergedRootType = new ObjectTypeDefinitionNode ( null, new NameNode(operationType.ToString()), null, Array.Empty <DirectiveNode>(), Array.Empty <NamedTypeNode>(), fields ); context.AddType(mergedRootType); } } else { _next.Invoke(context, types); } } }
private static void MergeNextType( ISchemaMergeContext context, List <EnumTypeInfo> notMerged) { EnumTypeInfo left = notMerged[0]; var leftValueSet = new HashSet <string>( left.Definition.Values.Select(t => t.Name.Value)); var readyToMerge = new List <EnumTypeInfo>(); readyToMerge.Add(left); for (int i = 1; i < notMerged.Count; i++) { if (CanBeMerged(leftValueSet, notMerged[i].Definition)) { readyToMerge.Add(notMerged[i]); } } MergeType(context, readyToMerge); notMerged.RemoveAll(readyToMerge.Contains); }
public void Merge( ISchemaMergeContext context, IReadOnlyList <ITypeInfo> types) { if (types.OfType <EnumTypeInfo>().Any()) { var notMerged = types.OfType <EnumTypeInfo>().ToList(); bool hasLeftovers = types.Count > notMerged.Count; while (notMerged.Count > 0) { MergeNextType(context, notMerged); } if (hasLeftovers) { _next.Invoke(context, types.NotOfType <EnumTypeInfo>()); } } else { _next.Invoke(context, types); } }
public static NameString CreateName <T>( ISchemaMergeContext context, IReadOnlyList <T> types) where T : ITypeInfo { NameString name = types[0].Definition.Name.Value; if (context.ContainsType(name)) { for (int i = 0; i < types.Count; i++) { name = types[i].CreateUniqueName(); if (!context.ContainsType(name)) { break; } } if (context.ContainsType(name)) { name = types[0].Definition.Name.Value; for (int i = 0; i < _maxRetries; i++) { NameString n = name + $"_{i}"; if (!context.ContainsType(name)) { name = n; break; } } } } return(name); }
public static NameString CreateName <T>( ISchemaMergeContext context, params T[] types) where T : ITypeInfo => CreateName(context, (IReadOnlyList <T>)types);
protected abstract void MergeTypes( ISchemaMergeContext context, IReadOnlyList <T> types, NameString newTypeName);