Exemplo n.º 1
0
        public static void RegisterDirective(this GraphQLModule module, string name, MethodInfo signature,
                                             DirectiveLocation locations, string description = null, Type handlerType = null, bool listInSchema = true)
        {
            if (signature == null)
            {
                throw new ArgumentException("RegisterDirective method: signature parameter may not be null.");
            }
            var reg = new DirectiveRegistration()
            {
                Name = name, Signature = signature, Locations = locations, Description = description, ListInSchema = listInSchema
            };

            module.Directives.Add(reg);
            if (handlerType != null)
            {
                module.DirectiveHandlers.Add(new DirectiveHandlerInfo()
                {
                    Name = name, Type = handlerType
                });
            }
        }
Exemplo n.º 2
0
        public static void RegisterDirective(this GraphQLModule module, string name, Type directiveAttributeType,
                                             DirectiveLocation locations, string description = null, Type handlerType = null, bool listInSchema = true)
        {
            if (!typeof(BaseDirectiveAttribute).IsAssignableFrom(directiveAttributeType))
            {
                throw new ArgumentException(
                          $"RegisterDirective method: directive attribute must be subclass of {nameof(directiveAttributeType)}");
            }
            var reg = new DirectiveRegistration()
            {
                Name = name, AttributeType = directiveAttributeType, Locations = locations, Description = description, ListInSchema = listInSchema
            };

            module.Directives.Add(reg);
            if (handlerType != null)
            {
                module.DirectiveHandlers.Add(new DirectiveHandlerInfo()
                {
                    Name = name, Type = handlerType
                });
            }
        }