Beispiel #1
0
            // Coerces a scalar value
            static object ParseValueScalar(ScalarGraphType scalarGraphType, VariableName variableName, object value)
            {
                if (value == null)
                {
                    return(null);
                }

                object ret;

                try
                {
                    ret = scalarGraphType.ParseValue(value);
                }
                catch (Exception ex)
                {
                    throw new InvalidVariableError(variableName, $"Unable to convert '{value}' to '{scalarGraphType.Name}'", ex);
                }

                if (ret == null)
                {
                    throw new InvalidVariableError(variableName, $"Unable to convert '{value}' to '{scalarGraphType.Name}'");
                }

                return(ret);
            }
Beispiel #2
0
 public string PrintType(IGraphType type)
 {
     return(type switch
     {
         EnumerationGraphType graphType => PrintEnum(graphType),
         ScalarGraphType scalarGraphType => PrintScalar(scalarGraphType),
         IObjectGraphType objectGraphType => PrintObject(objectGraphType),
         IInterfaceGraphType interfaceGraphType => PrintInterface(interfaceGraphType),
         UnionGraphType unionGraphType => PrintUnion(unionGraphType),
         DirectiveGraphType directiveGraphType => PrintDirective(directiveGraphType),  //TODO: DirectiveGraphType does not inherit IGraphType
         IInputObjectGraphType input => PrintInputObject(input),
         _ => throw new InvalidOperationException($"Unknown GraphType '{type.GetType().Name}' with name '{type.Name}'")
     });
        /// <summary>
        /// Builds an execution node with the specified parameters.
        /// </summary>
        protected ExecutionNode BuildSubscriptionExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, int?indexInParentNode, object source)
        {
            if (graphType is NonNullGraphType nonNullFieldType)
            {
                graphType = nonNullFieldType.ResolvedType;
            }

            return(graphType switch
            {
                ListGraphType _ => new SubscriptionArrayExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source),
                IObjectGraphType _ => new SubscriptionObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source),
                IAbstractGraphType _ => new SubscriptionObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode, source),
                ScalarGraphType scalarGraphType => new SubscriptionValueExecutionNode(parent, scalarGraphType, field, fieldDefinition, indexInParentNode, source),
                _ => throw new InvalidOperationException($"Unexpected type: {graphType}")
            });
        public static ExecutionNode BuildExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, int?indexInParentNode = null)
        {
            if (graphType is NonNullGraphType nonNullFieldType)
            {
                graphType = nonNullFieldType.ResolvedType;
            }

            return(graphType switch
            {
                ListGraphType _ => new ArrayExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode),
                IObjectGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode),
                IAbstractGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode),
                ScalarGraphType _ => new ValueExecutionNode(parent, graphType, field, fieldDefinition, indexInParentNode),
                _ => throw new InvalidOperationException($"Unexpected type: {graphType}")
            });
        public static ExecutionNode BuildExecutionNode(ExecutionNode parent, IGraphType graphType, Field field, FieldType fieldDefinition, string[] path = null)
        {
            path ??= AppendPath(parent.Path, field.Name);

            if (graphType is NonNullGraphType nonNullFieldType)
            {
                graphType = nonNullFieldType.ResolvedType;
            }

            return(graphType switch
            {
                ListGraphType _ => new ArrayExecutionNode(parent, graphType, field, fieldDefinition, path),
                IObjectGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, path),
                IAbstractGraphType _ => new ObjectExecutionNode(parent, graphType, field, fieldDefinition, path),
                ScalarGraphType _ => new ValueExecutionNode(parent, graphType, field, fieldDefinition, path),
                _ => throw new InvalidOperationException($"Unexpected type: {graphType}")
            });
 public void VisitScalar(ScalarGraphType scalar, ISchema schema) => ValidateAppliedDirectives(scalar, schema, DirectiveLocation.Scalar);
 /// <summary>
 /// Initializes an instance of <see cref="ValueExecutionNode"/> with the specified values.
 /// </summary>
 public ValueExecutionNode(ExecutionNode parent, ScalarGraphType graphType, GraphQLField field, FieldType fieldDefinition, int?indexInParentNode)
     : base(parent, graphType, field, fieldDefinition, indexInParentNode)
 {
 }
Beispiel #8
0
        public string PrintScalar(ScalarGraphType type)
        {
            var description = Options.IncludeDescriptions ? PrintDescription(type.Description) : "";

            return(description + "scalar {0}".ToFormat(type.Name));
        }
Beispiel #9
0
 public virtual void VisitScalar(ScalarGraphType scalar)
 {
 }
 public SubscriptionValueExecutionNode(ExecutionNode parent, ScalarGraphType graphType, Field field, FieldType fieldDefinition, int?indexInParentNode, object source)
     : base(parent, graphType, field, fieldDefinition, indexInParentNode)
 {
     Source = source;
 }
 /// <inheritdoc />
 public virtual void VisitScalar(ScalarGraphType type, ISchema schema)
 {
 }
 public string PrintScalar(ScalarGraphType type)
 {
     return("scalar {0}".ToFormat(type.Name));
 }
 /// <inheritdoc/>
 public void VisitScalar(ScalarGraphType type, ISchema schema) => ValidateAppliedDirectives(type, null, null, schema, DirectiveLocation.Scalar);
 /// <inheritdoc/>
 public virtual void VisitScalar(ValidationContext context, VariableDefinition variable, VariableName variableName, ScalarGraphType type, object?variableValue, object?parsedValue)
 {
 }
        public string PrintScalar(ScalarGraphType type)
        {
            var description = PrintDescription(type.Description);

            return(description + "scalar {0}".ToFormat(type.Name));
        }
 public void VisitScalar(ValidationContext context, VariableDefinition variable, VariableName variableName, ScalarGraphType type, object?variableValue, object?parsedValue)
 {
     foreach (var visitor in _visitors)
     {
         visitor.VisitScalar(context, variable, variableName, type, variableValue, parsedValue);
     }
 }
 public override void VisitScalar(ScalarGraphType type, ISchema schema) => SetDescription(type);
 public override void VisitScalar(ScalarGraphType scalar, ISchema schema) => SetDescription(scalar);