示例#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));
                }
            }
        }
        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));
                }
            }
        }