-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a lightweight mutable schema. (#5854)
- Loading branch information
1 parent
053e304
commit 33072a7
Showing
48 changed files
with
4,012 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
102
src/HotChocolate/Skimmed/src/Skimmed/DirectiveCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
Oops, something went wrong.