예제 #1
0
        public void Validate(IDirectiveContext context)
        {
            foreach (InputField argument in context.Field.Arguments)
            {
                foreach (IDirective directive in argument.Directives)
                {
                    object argumentValue =
                        context.Argument <object>(argument.Name);

                    var argumentValidator =
                        directive.ToObject <ArgumentValidationDirective>();

                    argumentValidator.Validator(
                        context, context.FieldSelection,
                        argument.Name, argumentValue);
                }
            }
        }
예제 #2
0
        // TODO : rework and finalize
        private static IReadOnlyDictionary <string, object> CreateVariables(
            IDirectiveContext directiveContext,
            IEnumerable <SelectionPathComponent> components)
        {
            var root = new Dictionary <string, object>();

            foreach (var component in components)
            {
                foreach (ArgumentNode argument in component.Arguments)
                {
                    if (argument.Value is ScopedVariableNode sv)
                    {
                        switch (sv.Scope.Value)
                        {
                        case "arguments":
                            root[sv.ToVariableName()] =
                                directiveContext.Argument <object>(
                                    sv.Name.Value);
                            break;

                        case "variables":
                            break;

                        case "properties":
                            root[sv.ToVariableName()] = directiveContext
                                                        .Parent <IDictionary <string, object> >()
                                                        [sv.Name.Value];
                            break;

                        default:
                            throw new NotSupportedException();
                        }
                    }
                }
            }

            return(root);
        }