Skip to content

Commit

Permalink
Adds a lightweight mutable schema. (#5854)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Feb 20, 2023
1 parent 053e304 commit 33072a7
Show file tree
Hide file tree
Showing 48 changed files with 4,012 additions and 1 deletion.
1 change: 1 addition & 0 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static class Helpers
Path.Combine("HotChocolate", "MongoDb"),
Path.Combine("HotChocolate", "Neo4J"),
Path.Combine("HotChocolate", "Raven"),
Path.Combine("HotChocolate", "Skimmed"),
Path.Combine("HotChocolate", "Stitching"),
Path.Combine("HotChocolate", "Fusion"),
Path.Combine("HotChocolate", "Spatial"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HotChocolate.Types;
public interface IHasDescription
{
/// <summary>
/// Gets the description of the object.
/// Gets the description of the type system member.
/// </summary>
string? Description { get; }
}
36 changes: 36 additions & 0 deletions src/HotChocolate/Skimmed/HotChocolate.Skimmed.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6E3706EB-D2C3-43AB-BCBB-C573E7FD5037}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skimmed", "src\Skimmed\Skimmed.csproj", "{B0BBF585-476F-406F-8C96-405871F5FB6E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FABE2699-4BCE-4484-AB62-4AB107B669AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Skimmed.Tests", "test\Skimmed.Tests\Skimmed.Tests.csproj", "{A5057872-F820-4594-9C43-B8DA1FCFF7D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0BBF585-476F-406F-8C96-405871F5FB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0BBF585-476F-406F-8C96-405871F5FB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0BBF585-476F-406F-8C96-405871F5FB6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0BBF585-476F-406F-8C96-405871F5FB6E}.Release|Any CPU.Build.0 = Release|Any CPU
{A5057872-F820-4594-9C43-B8DA1FCFF7D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5057872-F820-4594-9C43-B8DA1FCFF7D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5057872-F820-4594-9C43-B8DA1FCFF7D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5057872-F820-4594-9C43-B8DA1FCFF7D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B0BBF585-476F-406F-8C96-405871F5FB6E} = {6E3706EB-D2C3-43AB-BCBB-C573E7FD5037}
{A5057872-F820-4594-9C43-B8DA1FCFF7D7} = {FABE2699-4BCE-4484-AB62-4AB107B669AC}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions src/HotChocolate/Skimmed/src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Nullable.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<TargetFrameworks>$(Library2TargetFrameworks)</TargetFrameworks>
<NoWarn>$(NoWarn);CA1812</NoWarn>
</PropertyGroup>

</Project>
37 changes: 37 additions & 0 deletions src/HotChocolate/Skimmed/src/Skimmed/Argument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HotChocolate.Language;
using HotChocolate.Utilities;

namespace HotChocolate.Skimmed;

public sealed class Argument
{
public Argument(string name, string value)
: this(name, new StringValueNode(value))
{
}

public Argument(string name, int value)
: this(name, new IntValueNode(value))
{
}

public Argument(string name, double value)
: this(name, new FloatValueNode(value))
{
}

public Argument(string name, bool value)
: this(name, new BooleanValueNode(value))
{
}

public Argument(string name, IValueNode value)
{
Name = name.EnsureGraphQLName();
Value = value;
}

public string Name { get; }

public IValueNode Value { get; }
}
31 changes: 31 additions & 0 deletions src/HotChocolate/Skimmed/src/Skimmed/ComplexType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using HotChocolate.Utilities;

namespace HotChocolate.Skimmed;

public abstract class ComplexType : INamedType
{
private string _name;

protected ComplexType(string name)
{
_name = name.EnsureGraphQLName();
}

public abstract TypeKind Kind { get; }

public string Name
{
get => _name;
set => _name = value.EnsureGraphQLName();
}

public string? Description { get; set; }

public DirectiveCollection Directives { get; } = new();

public IList<InterfaceType> Implements { get; } = new List<InterfaceType>();

public FieldCollection<OutputField> Fields { get; } = new();

public IDictionary<string, object?> ContextData { get; } = new Dictionary<string, object?>();
}
21 changes: 21 additions & 0 deletions src/HotChocolate/Skimmed/src/Skimmed/Directive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace HotChocolate.Skimmed;

public sealed class Directive
{
public Directive(DirectiveType type, params Argument[] arguments)
: this(type, (IReadOnlyList<Argument>)arguments)
{
}

public Directive(DirectiveType type, IReadOnlyList<Argument> arguments)
{
Type = type;
Arguments = arguments;
}

public string Name => Type.Name;

public DirectiveType Type { get; }

public IReadOnlyList<Argument> Arguments { get; }
}
102 changes: 102 additions & 0 deletions src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.Collections;
using HotChocolate.Utilities;

namespace HotChocolate.Skimmed;

/// <summary>
/// Represents a collection of directives.
/// </summary>
public sealed class DirectiveCollection : ICollection<Directive>
{
private readonly List<Directive> _directives = new();

public int Count => _directives.Count;

public bool IsReadOnly => false;

public IEnumerable<Directive> this[string directiveName]
{
get
{
var directives = _directives;
return directives.Count == 0
? Enumerable.Empty<Directive>()
: FindDirectives(directives, directiveName);
}
}

private static IEnumerable<Directive> FindDirectives(List<Directive> directives, string name)
{
for (var i = 0; i < directives.Count; i++)
{
var directive = directives[i];

if (directive.Name.EqualsOrdinal(name))
{
yield return directive;
}
}
}

public Directive? FirstOrDefault(string name)
{
var directives = _directives;

for (var i = 0; i < directives.Count; i++)
{
var directive = directives[i];

if (directive.Name.EqualsOrdinal(name))
{
return directive;
}
}

return null;
}

public bool ContainsName(string directiveName)
=> FirstOrDefault(directiveName) is not null;

public bool Contains(Directive item)
=> _directives.Contains(item);

public void Add(Directive item)
=> _directives.Add(item);

public bool Replace(Directive currentDirective, Directive newDirective)
{
for (var i = 0; i < _directives.Count; i++)
{
if (ReferenceEquals(_directives[i], currentDirective))
{
_directives[i] = newDirective;
return true;
}
}

return false;
}

public bool Remove(Directive item)
=> _directives.Remove(item);

public void Clear()
=> _directives.Clear();

public void CopyTo(Directive[] array, int arrayIndex)
{
foreach (var directive in _directives)
{
array[arrayIndex++] = directive;
}
}

/// <inheritdoc />
public IEnumerator<Directive> GetEnumerator()
=> ((IEnumerable<Directive>)_directives).GetEnumerator();

IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();

}
Loading

0 comments on commit 33072a7

Please sign in to comment.