/// <summary> /// Processes the given request against this instance /// performing the source data conversion operation as defined by this entity and generating a response. /// </summary> /// <param name="data">The actual data read from the query document.</param> /// <returns>The final native value of the converted data.</returns> public override object Resolve(ReadOnlySpan <char> data) { if (Guid.TryParse(GraphQLStrings.UnescapeAndTrimDelimiters(data), out var guid)) { return(guid); } throw new UnresolvedValueException(data); }
public void SpanToString(string inputText, string expectedOutput) { var result = GraphQLStrings.UnescapeAndTrimDelimiters(inputText); Assert.AreEqual( expectedOutput, result, $"Expected '{expectedOutput}' but got '{result}'"); }
/// <summary> /// Processes the given request against this instance /// performing the source data conversion operation as defined by this entity and generating a response. /// </summary> /// <param name="data">The actual data read from the query document.</param> /// <returns>The final native value of the converted data.</returns> public override object Resolve(ReadOnlySpan <char> data) { var output = GraphQLStrings.UnescapeAndTrimDelimiters(data, true); if (output == null) { throw new UnresolvedValueException(data); } return(new GraphId(output)); }
/// <summary> /// Processes the given request against this instance /// performing the source data conversion operation as defined by this entity and generating a response. /// </summary> /// <param name="data">The actual data read from the query document.</param> /// <returns>The final native value of the converted data.</returns> public override object Resolve(ReadOnlySpan <char> data) { var value = GraphQLStrings.UnescapeAndTrimDelimiters(data); // don't make any assumptions about the uri other than if it can be a uri // or not. "-3" is a valid uri but is not a web address. At this point // we can't deteremine if the user intended a web address be supplied or not if (Uri.IsWellFormedUriString(value, UriKind.RelativeOrAbsolute) && Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var result)) { return(result); } throw new UnresolvedValueException(data); }
/// <summary> /// Processes the given request against this instance /// performing the source data conversion operation as defined by this entity and generating a response. /// </summary> /// <param name="data">The actual data read from the query document.</param> /// <returns>The final native value of the converted data.</returns> public override object Resolve(ReadOnlySpan <char> data) { if (DateTimeExtensions.TryParseMultiFormat( GraphQLStrings.UnescapeAndTrimDelimiters(data, false), out DateTime? dt) && dt.HasValue) { if (dt.Value.Kind == DateTimeKind.Unspecified && this.DefaultKind != DateTimeKind.Unspecified) { dt = DateTime.SpecifyKind(dt.Value, this.DefaultKind); } return(dt.Value); } throw new UnresolvedValueException(data); }
/// <summary> /// Resolves the provided query input value to the .NET object rendered by this resolver. /// This input value is garunteed to not be a variable reference. /// </summary> /// <param name="resolvableItem">The resolvable item.</param> /// <returns>System.Object.</returns> protected override object ResolveFromItem(IResolvableItem resolvableItem) { string value = null; try { if (resolvableItem is IResolvableValue resolvableValue) { // enums may be as delimited strings (read from variables collection) // or as non-delimited strings (read from a query document) value = GraphQLStrings.UnescapeAndTrimDelimiters(resolvableValue.ResolvableValue, false); return(Enum.Parse(_enumType, value, true)); } } catch { // ignored } return(null); }