/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { // at this stage we know thta we've encountered a complexvalue node // we can also garuntee that the active input value on the request is going to be the value container // for that ComplexvalueNode. It is to that container that we are adding a new argument. // // take for instance this sequence: // // field(arg1: {childArg1: "value" childArg2: value} ) // // we are pointing at the argument "arg1" // which is a complexargument type having a value of QueryComplexInputValue which is a container of arguments // it is to that container that we are adding this new argument "childArg1" indicated by this InputItemNode // on the context. // // Note: this operation could be nested N levels deep such as with // field(arg1: { childArg1: {subChildArg1: value, subChildArg1: value} childArg2: 5} ) // the scenario would be valid for: // adding childArg1 or childArg2 to arg1 // adding subChildArg1 or subChildArg2 to childArg1 var node = (InputItemNode)context.ActiveNode; var inputObject = context.FindContextItem <QueryInputValue>() as QueryComplexInputValue; var ownerGraphType = inputObject.OwnerArgument.GraphType as IInputObjectGraphType; var field = ownerGraphType.Fields[node.InputName.ToString()]; var graphType = context.DocumentContext.Schema.KnownTypes.FindGraphType(field); var argument = new QueryInputArgument(node, graphType, field.TypeExpression); context.AddDocumentPart(argument); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var fragmentNode = (FragmentNode)context.ActiveNode; var queryFragment = new QueryFragment(fragmentNode); context.AddDocumentPart(queryFragment); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (VariableNode)context.ActiveNode; var queryVariable = new QueryVariable(node); context.AddDocumentPart(queryVariable); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { // for whatever the active argument in context is // it could be an argument on a field, on a directive or // even an argument that is part of a nested input object inside a field argument set // make a value container for the active value // then add it to the context. var node = (InputValueNode)context.ActiveNode; var queryValue = QueryInputValueFactory.CreateInputValue(node); context.AddDocumentPart(queryValue); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (InputItemNode)context.ActiveNode; var queryDirective = context.FindContextItem <QueryDirective>(); var fieldArg = queryDirective.Directive.Arguments[node.InputName.ToString()]; var graphType = context.DocumentContext.Schema.KnownTypes.FindGraphType(fieldArg.TypeExpression.TypeName); var argument = new QueryInputArgument(node, graphType, fieldArg.TypeExpression); context.AddDocumentPart(argument); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (FragmentSpreadNode)context.ActiveNode; QueryFragment fragment = context.DocumentContext.Fragments.FindFragment(node.PointsToFragmentName.ToString()); context.AddDocumentPart(fragment); fragment.MarkAsReferenced(); context.AppendNodes(fragment.Node.Children); context.BeginNewDocumentScope(); context.DocumentScope.RestrictFieldsToGraphType(fragment.GraphType); return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (DirectiveNode)context.ActiveNode; var directive = context.DocumentContext.Schema.KnownTypes.FindGraphType(node.DirectiveName.ToString()) as IDirectiveGraphType; if (directive == null) { return(false); } var location = node.ParentNode?.DirectiveLocation() ?? DirectiveLocation.NONE; var queryDirective = new QueryDirective(node, directive, location); context.AddDocumentPart(queryDirective); return(true); }
/// <summary> /// Validates the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (OperationTypeNode)context.ActiveNode; var operationType = Constants.ReservedNames.FindOperationTypeByKeyword(node.OperationType.ToString()); if (!context.DocumentContext.Schema.OperationTypes.ContainsKey(operationType)) { return(false); } var operation = context.DocumentContext.Schema.OperationTypes[operationType]; var queryOperation = new QueryOperation(node, operationType, operation); context.AddDocumentPart(queryOperation); return(true); }
/// <summary> /// Validates the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (FieldNode)context.ActiveNode; // the '__typename' field is a known static quantity that requires no special rule processing or validation // it just exists or it doesn't and would be valid on any graph type returning it. // Group the appropriate logic for this metafield here to account for the allowed exception in spec rule 5.3.1 // where unions can contain a field reference for '__typename' var allTypes = context.DocumentContext.Schema.KnownTypes.ExpandAbstractType(context.GraphType); foreach (var graphType in allTypes) { if (graphType == null) { continue; } IGraphField field = null; if (graphType is IGraphFieldContainer fieldContainer) { field = fieldContainer.Fields.FindField(node.FieldName.ToString()); } if (field == null) { // if the graph type doesnt contain fields (scalar or enum?) this its an error. // this shouldnt happen because of schema building and validation but just in case... this.ValidationError( context, $"The graph type '{graphType.Name}' does not contain a field named '{node.FieldName.ToString()}'."); continue; } var fieldSelection = new FieldSelection(node, field, graphType); context.AddDocumentPart(fieldSelection); } return(true); }
/// <summary> /// Executes the construction step the specified node to ensure it is "correct" in the context of the rule doing the valdiation. /// </summary> /// <param name="context">The validation context encapsulating a <see cref="SyntaxNode" /> that needs to be validated.</param> /// <returns><c>true</c> if the node is valid, <c>false</c> otherwise.</returns> public override bool Execute(DocumentConstructionContext context) { var node = (FieldNode)context.ActiveNode; var searchContainer = context.GraphType as IGraphFieldContainer; if (searchContainer == null) { return(false); } var field = searchContainer.Fields.FindField(node.FieldName.ToString()); var graphType = context.DocumentContext.Schema.KnownTypes.FindGraphType(field); if (graphType == null) { throw new InvalidOperationException($"A field named '{node.FieldName.ToString()}' was expected but was not valid in context."); } var fieldSelection = new FieldSelection(node, field, graphType); context.AddDocumentPart(fieldSelection); return(true); }