Пример #1
0
        private MergeDirectiveRuleDelegate CompileMergeDirectiveDelegate()
        {
            MergeDirectiveRuleDelegate current = (c, t) =>
            {
                if (t.Count > 0)
                {
                    throw new NotSupportedException(
                              "The type definitions could not be handled.");
                }
            };

            return(new DirectiveTypeMergeHandler(current).Merge);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public DocumentNode Merge()
        {
            MergeTypeRuleDelegate       mergeTypes      = CompileMergeTypeDelegate();
            MergeDirectiveRuleDelegate  mergeDirectives = CompileMergeDirectiveDelegate();
            IReadOnlyList <ISchemaInfo> schemas         = CreateSchemaInfos();

            var context = new SchemaMergeContext();

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

            // merge all other types
            MergeTypes(context, CreateTypesNameSet(schemas), schemas, mergeTypes);
            MergeDirectives(context, CreateDirectivesNameSet(schemas), schemas, mergeDirectives);

            return(RewriteTypeReferences(schemas, context.CreateSchema()));
        }
Пример #4
0
        private MergeDirectiveRuleDelegate CompileMergeDirectiveDelegate()
        {
            MergeDirectiveRuleDelegate current = (c, t) =>
            {
                if (t.Count > 0)
                {
                    throw new NotSupportedException(
                              "The type definitions could not be handled.");
                }
            };

            var handlers = new List <MergeDirectiveRuleFactory>();

            handlers.AddRange(_directiveMergeRules);
            handlers.Add(c => new DirectiveTypeMergeHandler(c).Merge);

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

            return(current);
        }
Пример #5
0
 public CustomDirectiveMergeHandler(MergeDirectiveRuleDelegate next)
 {
 }
 public DirectiveTypeMergeHandler(MergeDirectiveRuleDelegate next)
 {
     _next = next ?? throw new ArgumentNullException(nameof(next));
 }
 public MergeDirectivesHandler(MergeDirectiveRuleDelegate next) => _next = next;