Skip to content

Commit

Permalink
Spatial types (#1870)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Staib <michael@chillicream.com>
Co-authored-by: Moritz Brandes <mb@grannyandsmith.com>
Co-authored-by: John Brandes <john.brandes0x@gmail.com>
Co-authored-by: steveoh <sgourley@utah.gov>
  • Loading branch information
5 people committed May 29, 2020
1 parent 2c42626 commit c26221c
Show file tree
Hide file tree
Showing 88 changed files with 5,937 additions and 37 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
@@ -0,0 +1 @@
"args": [],
33 changes: 7 additions & 26 deletions src/HotChocolate/Core/src/Types/Types/InputObjectType.cs
Expand Up @@ -27,8 +27,7 @@ protected InputObjectType()
_configure = Configure;
}

public InputObjectType(
Action<IInputObjectTypeDescriptor> configure)
public InputObjectType(Action<IInputObjectTypeDescriptor> configure)
{
_configure = configure
?? throw new ArgumentNullException(nameof(configure));
Expand All @@ -40,9 +39,7 @@ protected InputObjectType()

public FieldCollection<InputField> Fields { get; private set; }

#region IInputType

public bool IsInstanceOfType(IValueNode literal)
public virtual bool IsInstanceOfType(IValueNode literal)
{
if (literal == null)
{
Expand All @@ -53,7 +50,7 @@ public bool IsInstanceOfType(IValueNode literal)
|| literal is NullValueNode;
}

public object ParseLiteral(IValueNode literal)
public virtual object ParseLiteral(IValueNode literal)
{
if (literal is null)
{
Expand All @@ -74,7 +71,7 @@ public object ParseLiteral(IValueNode literal)
TypeResources.InputObjectType_CannotParseLiteral);
}

public bool IsInstanceOfType(object value)
public virtual bool IsInstanceOfType(object value)
{
if (value is null)
{
Expand All @@ -84,7 +81,7 @@ public bool IsInstanceOfType(object value)
return ClrType.IsInstanceOfType(value);
}

public IValueNode ParseValue(object value)
public virtual IValueNode ParseValue(object value)
{
if (value is null)
{
Expand Down Expand Up @@ -133,19 +130,9 @@ public virtual bool TrySerialize(object value, out object serialized)

public object Deserialize(object serialized)
{
if (serialized is null)
{
return null;
}

if (serialized is IReadOnlyDictionary<string, object> dict)
{
return _deserialize(dict);
}

if (ClrType != typeof(object) && ClrType.IsInstanceOfType(serialized))
if (TryDeserialize(serialized, out object deserialized))
{
return serialized;
return deserialized;
}

throw new InputObjectSerializationException(
Expand Down Expand Up @@ -184,10 +171,6 @@ public virtual bool TryDeserialize(object serialized, out object value)
}
}

#endregion

#region Initialization

protected override InputObjectTypeDefinition CreateDefinition(
IInitializationContext context)
{
Expand Down Expand Up @@ -262,7 +245,5 @@ protected virtual void Configure(IInputObjectTypeDescriptor descriptor)
fields.Add(new InputField(fieldDefinition));
}
}

#endregion
}
}
17 changes: 8 additions & 9 deletions src/HotChocolate/Core/src/Types/Types/Scalars/ScalarType.cs
Expand Up @@ -23,7 +23,6 @@ public abstract class ScalarType
private readonly ITypeConversion _converter = TypeConversion.Default;
private readonly ExtensionData _contextData = new ExtensionData();


/// <summary>
/// Initializes a new instance of the
/// <see cref="T:HotChocolate.Types.ScalarType"/> class.
Expand Down Expand Up @@ -86,7 +85,7 @@ protected ScalarType(NameString name, BindingBehavior bind = BindingBehavior.Exp
/// <c>true</c> if the value is a value of this type;
/// otherwise, <c>false</c>.
/// </returns>
public virtual bool IsInstanceOfType(object value)
public virtual bool IsInstanceOfType(object? value)
{
if (value is null)
{
Expand All @@ -110,7 +109,7 @@ public virtual bool IsInstanceOfType(object value)
/// The specified <paramref name="literal" /> cannot be parsed
/// by this scalar.
/// </exception>
public abstract object ParseLiteral(IValueNode literal);
public abstract object? ParseLiteral(IValueNode literal);

/// <summary>
/// Parses the .net value representation to a value literal.
Expand All @@ -125,7 +124,7 @@ public virtual bool IsInstanceOfType(object value)
/// The specified <paramref name="value" /> cannot be parsed
/// by this scalar.
/// </exception>
public abstract IValueNode ParseValue(object value);
public abstract IValueNode ParseValue(object? value);

/// <summary>
/// Serializes the .net value representation.
Expand All @@ -140,9 +139,9 @@ public virtual bool IsInstanceOfType(object value)
/// The specified <paramref name="value" /> cannot be serialized
/// by this scalar.
/// </exception>
public virtual object Serialize(object value)
public virtual object Serialize(object? value)
{
if (TrySerialize(value, out object s))
if (TrySerialize(value, out object? s))
{
return s;
}
Expand All @@ -163,7 +162,7 @@ public virtual object Serialize(object value)
/// <returns>
/// <c>true</c> if the value was correctly serialized; otherwise, <c>false</c>.
/// </returns>
public abstract bool TrySerialize(object value, out object serialized);
public abstract bool TrySerialize(object? value, out object? serialized);

/// <summary>
/// Deserializes the serialized value to it`s .net value representation.
Expand All @@ -178,7 +177,7 @@ public virtual object Serialize(object value)
/// The specified <paramref name="value" /> cannot be deserialized
/// by this scalar.
/// </exception>
public virtual object Deserialize(object serialized)
public virtual object Deserialize(object? serialized)
{
if (TryDeserialize(serialized, out object v))
{
Expand All @@ -202,7 +201,7 @@ public virtual object Deserialize(object serialized)
/// <returns>
/// <c>true</c> if the serialized value was correctly deserialized; otherwise, <c>false</c>.
/// </returns>
public abstract bool TryDeserialize(object serialized, out object value);
public abstract bool TryDeserialize(object? serialized, out object? value);

internal sealed override void Initialize(IInitializationContext context)
{
Expand Down
6 changes: 4 additions & 2 deletions src/HotChocolate/Core/src/Types/Types/Scalars/ScalarType~1.cs
@@ -1,5 +1,7 @@
using System;

#nullable enable

namespace HotChocolate.Types
{
/// <summary>
Expand All @@ -17,7 +19,7 @@ protected ScalarType(NameString name, BindingBehavior bind = BindingBehavior.Exp

public sealed override Type ClrType => typeof(TClrType);

public override bool TrySerialize(object value, out object serialized)
public override bool TrySerialize(object? value, out object? serialized)
{
if (value is null)
{
Expand All @@ -35,7 +37,7 @@ public override bool TrySerialize(object value, out object serialized)
return false;
}

public override bool TryDeserialize(object serialized, out object value)
public override bool TryDeserialize(object? serialized, out object? value)
{
if (serialized is null)
{
Expand Down
24 changes: 24 additions & 0 deletions src/HotChocolate/Spatial/.vscode/tasks.json
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

0 comments on commit c26221c

Please sign in to comment.