コード例 #1
0
        private void CompleteDirective(
            ITypeInitializationContext context,
            DirectiveDescription description,
            HashSet <string> processed)
        {
            DirectiveReference reference =
                DirectiveReference.FromDescription(description);
            DirectiveType directiveType = context.GetDirectiveType(reference);

            if (directiveType != null)
            {
                if (!processed.Add(directiveType.Name) &&
                    !directiveType.IsRepeatable)
                {
                    context.ReportError(new SchemaError(
                                            $"The specified directive `@{directiveType.Name}` " +
                                            "is unique and cannot be added twice.",
                                            context.Type as INamedType));
                }
                else if (directiveType.Locations.Contains(_location))
                {
                    _directives.Add(Directive.FromDescription(
                                        directiveType, description, _source));
                }
                else
                {
                    context.ReportError(new SchemaError(
                                            $"The specified directive `@{directiveType.Name}` " +
                                            "is not allowed on the current location " +
                                            $"`{_location}`.",
                                            context.Type as INamedType));
                }
            }
        }
コード例 #2
0
        public DirectiveType GetDirectiveType(
            DirectiveReference directiveReference)
        {
            if (directiveReference == null)
            {
                throw new ArgumentNullException(nameof(directiveReference));
            }

            return(_schemaContext.Directives
                   .GetDirectiveType(directiveReference));
        }
コード例 #3
0
        private void CompleteDirecive(
            ITypeInitializationContext context,
            DirectiveDescription description)
        {
            DirectiveReference reference =
                DirectiveReference.FromDescription(description);
            DirectiveType type = context.GetDirectiveType(reference);

            if (type != null)
            {
                if (type.Locations.Contains(_location))
                {
                    _directives.Add(
                        Directive.FromDescription(type, description, _source));
                }
                else
                {
                    context.ReportError(new SchemaError(
                                            $"The specified directive `{type.Name}` is not " +
                                            $"allowed on the current location `{_location}`.",
                                            context.Type));
                }
            }
        }