Esempio n. 1
0
        private void MergeTypes(
            ISchemaMergeContext context,
            ISet <string> typeNames,
            IEnumerable <ISchemaInfo> schemas,
            MergeTypeRuleDelegate merge)
        {
            var types = new List <ITypeInfo>();

            foreach (string typeName in typeNames)
            {
                SetTypes(typeName, schemas, types);
                merge(context, types);
            }
        }
Esempio n. 2
0
        public DocumentNode Merge()
        {
            MergeTypeRuleDelegate       merge   = CompileMergeDelegate();
            IReadOnlyList <ISchemaInfo> schemas = CreateSchemaInfos();

            var context = new SchemaMergeContext();

            // merge root types
            MergeRootType(context, OperationType.Query, schemas, merge);
            MergeRootType(context, OperationType.Mutation, schemas, merge);
            MergeRootType(context, OperationType.Subscription, schemas, merge);

            // merge all other types
            MergeTypes(context, CreateNameSet(schemas), schemas, merge);

            return(RewriteTypeReferences(schemas, context.CreateSchema()));
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        private MergeTypeRuleDelegate CompileMergeTypeDelegate()
        {
            MergeTypeRuleDelegate current = (c, t) =>
            {
                if (t.Count > 0)
                {
                    throw new NotSupportedException(
                              "The type definitions could not be handled.");
                }
            };

            var handlers = new List <MergeTypeRuleFactory>();

            handlers.AddRange(_mergeRules);
            handlers.AddRange(_defaultMergeRules);

            for (int i = handlers.Count - 1; i >= 0; i--)
            {
                current = handlers[i].Invoke(current);
            }

            return(current);
        }
Esempio n. 5
0
 public ScalarTypeMergeHandler(MergeTypeRuleDelegate next)
 {
     _next = next ?? throw new ArgumentNullException(nameof(next));
 }
 public InputObjectTypeMergeHandler(MergeTypeRuleDelegate next)
     : base(next)
 {
 }
Esempio n. 7
0
 public CustomTypeMergeHandler(MergeTypeRuleDelegate next)
 {
 }
Esempio n. 8
0
 protected TypeMergeHanlderBase(MergeTypeRuleDelegate next)
 {
     _next = next ?? throw new ArgumentNullException(nameof(next));
 }
 public InterfaceTypeMergeHandler(MergeTypeRuleDelegate next)
     : base(next)
 {
 }
 public MergeTypesHandler(MergeTypeRuleDelegate next) => _next = next;