Exemplo n.º 1
0
        private bool TryLookupLocation(
            ISyntaxNode syntaxNode,
            out Types.DirectiveLocation location)
        {
            if (syntaxNode is FieldNode)
            {
                location = Types.DirectiveLocation.Field;
                return(true);
            }

            if (syntaxNode is FragmentDefinitionNode)
            {
                location = Types.DirectiveLocation.FragmentDefinition;
                return(true);
            }

            if (syntaxNode is FragmentSpreadNode)
            {
                location = Types.DirectiveLocation.FragmentSpread;
                return(true);
            }

            if (syntaxNode is InlineFragmentNode)
            {
                location = Types.DirectiveLocation.InlineFragment;
                return(true);
            }

            if (syntaxNode is OperationDefinitionNode o)
            {
                switch (o.Operation)
                {
                case OperationType.Query:
                    location = Types.DirectiveLocation.Query;
                    return(true);

                case OperationType.Mutation:
                    location = Types.DirectiveLocation.Mutation;
                    return(true);

                case OperationType.Subscription:
                    location = Types.DirectiveLocation.Subscription;
                    return(true);

                default:
                    location = default;
                    return(false);
                }
            }

            location = default;
            return(false);
        }
Exemplo n.º 2
0
 public static ISchemaError DirectiveCollection_LocationNotAllowed(
     DirectiveType directiveType,
     Types.DirectiveLocation location,
     ITypeSystemObject type,
     DirectiveNode?syntaxNode,
     object source) =>
 SchemaErrorBuilder.New()
 .SetMessage(
     TypeResources.DirectiveCollection_LocationNotAllowed,
     directiveType.Name,
     location)
 .SetCode(ErrorCodes.Schema.MissingType)
 .SetTypeSystemObject(type)
 .AddSyntaxNode(syntaxNode)
 .SetExtension("Source", source)
 .Build();