Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@defer support for StrawberryShake #4753

Merged
merged 33 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
169da68
Started Work on @defer for StrawberryShake
michaelstaib Feb 11, 2022
f3db2d9
Creates new defer map on the type model
michaelstaib Feb 13, 2022
148f08f
Finished Defer Analyzer Extensions
michaelstaib Feb 14, 2022
4a77dd4
Started work on connections
michaelstaib Feb 15, 2022
23f28bf
Merge branch 'main' into mst/strawberryshake-defer
michaelstaib Feb 21, 2022
2209bd4
Introduced new base class for result builders
michaelstaib Feb 21, 2022
097fb4c
dotnet format
michaelstaib Feb 22, 2022
a6c20ed
reworked code generation
michaelstaib Feb 22, 2022
6ac4cdd
.editorconfig
michaelstaib Feb 22, 2022
6d19b79
Fixed more code generators
michaelstaib Feb 22, 2022
0e68db9
Fixed snapshots
michaelstaib Feb 23, 2022
172180e
Updated More Tests
michaelstaib Feb 23, 2022
4b89c27
Fixed NetStandard Compatibility
michaelstaib Feb 23, 2022
3b5880c
Fixed Compile Issues
michaelstaib Feb 23, 2022
0698cc5
fixed more tests
michaelstaib Feb 23, 2022
01e54ee
cleanup
michaelstaib Feb 23, 2022
382457c
Fixed more tests
michaelstaib Feb 23, 2022
19dbf0a
Fixed File Issue in source gen
michaelstaib Feb 23, 2022
1c36385
Formatting
michaelstaib Feb 24, 2022
3b7da64
Fixed more issues
michaelstaib Feb 24, 2022
af7c362
Fixed tests
michaelstaib Feb 24, 2022
f2e98ca
Fixed more tests
michaelstaib Feb 24, 2022
708437d
Reworked Source Generator
michaelstaib Feb 24, 2022
bdbbf8e
Reworked code gen server interaction
michaelstaib Feb 24, 2022
b869ecf
Fixed compile error
michaelstaib Feb 24, 2022
d137362
Reworked Error Handling
michaelstaib Feb 24, 2022
7904fc8
Reworked Razor Components
michaelstaib Feb 24, 2022
8f49bad
Reworked Fragment Handling
michaelstaib Feb 25, 2022
7ecddb1
Added Metapackage
michaelstaib Feb 25, 2022
684574a
Fixed patching
michaelstaib Feb 25, 2022
eb1553f
cleanup
michaelstaib Feb 25, 2022
c7cc269
Added MyGet for testing
michaelstaib Feb 25, 2022
d982c68
Stream Results
michaelstaib Feb 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 18 additions & 2 deletions .build/Build.Publish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ partial class Build
// IEnumerable<string> ChangelogSectionNotes => ExtractChangelogSectionNotes(ChangelogFile);
[Parameter("NuGet Source for Packages")] readonly string NuGetSource = "https://api.nuget.org/v3/index.json";
[Parameter("NuGet Api Key")] readonly string NuGetApiKey;
[Parameter("NuGet Source for Packages")] readonly string MyGetSource = "https://www.myget.org/F/hotchocolate/api/v3/index.json";
[Parameter("MyGet Api Key")] readonly string MyGetApiKey;

Target Pack => _ => _
.DependsOn(PackLocal)
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Release));
.Requires(() => Configuration.Equals(Release))
.Executes(() =>
{
IReadOnlyCollection<AbsolutePath> packages = PackageDirectory.GlobFiles("*.nupkg");

DotNetNuGetPush(
_ => _
.SetSource(MyGetSource)
.SetApiKey(MyGetApiKey)
.CombineWith(
packages,
(_, v) => _.SetTargetPath(v)),
degreeOfParallelism: 2,
completeOnFailure: true);
});


Target PackLocal => _ => _
Expand All @@ -40,7 +56,7 @@ partial class Build

projFile = File.ReadAllText(EmptyAzf12Proj);
File.WriteAllText(EmptyAzf12Proj, projFile.Replace("11.1.0", GitVersion.SemVer));

DotNetBuildSonarSolution(
PackSolutionFile,
include: file =>
Expand Down
50 changes: 0 additions & 50 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -97,56 +97,6 @@ csharp_space_between_parentheses = false
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error

# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion

# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:error

# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

dotnet_style_require_accessibility_modifiers = always

# Public API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
<PackageReference Include="Microsoft.Toolkit.HighPerformance" Version="7.1.2" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
</ItemGroup>

Expand Down
63 changes: 17 additions & 46 deletions src/HotChocolate/Core/src/Abstractions/NameString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,15 @@ public NameString(string value)
/// <summary>
/// <c>true</c> if the name is not empty
/// </summary>
public bool HasValue
{
get
{
return !IsEmpty;
}
}
public bool HasValue => !IsEmpty;

public bool IsEmpty
{
get => string.IsNullOrEmpty(Value);
}
public bool IsEmpty => string.IsNullOrEmpty(Value);

/// <summary>
/// Provides the name string.
/// </summary>
/// <returns>The name string value</returns>
public override string ToString()
{
return Value;
}
public override string ToString() => Value;

/// <summary>
/// Appends a <see cref="NameString"/> to this
Expand All @@ -70,9 +58,7 @@ public override string ToString()
/// </summary>
/// <returns>The combined <see cref="NameString"/>.</returns>
public NameString Add(NameString other)
{
return new(Value + other.Value);
}
=> new(Value + other.Value);

/// <summary>
/// Compares this <see cref="NameString"/> value to another value
Expand All @@ -88,13 +74,7 @@ public NameString Add(NameString other)
/// <c>true</c> if both <see cref="NameString"/> values are equal.
/// </returns>
public bool Equals(NameString other, StringComparison comparisonType)
{
if (!HasValue && !other.HasValue)
{
return true;
}
return string.Equals(Value, other.Value, comparisonType);
}
=> (!HasValue && !other.HasValue) || string.Equals(Value, other.Value, comparisonType);

/// <summary>
/// Compares this <see cref="NameString"/> value to another value using
Expand Down Expand Up @@ -128,10 +108,13 @@ public override bool Equals(object? obj)
return obj is NameString n && Equals(n);
}

#if NET5_0_OR_GREATER
public int CompareTo(NameString other)
{
return string.Compare(Value, other.Value, StringComparison.Ordinal);
}
=> string.CompareOrdinal(Value, other.Value);
#else
public int CompareTo(NameString other)
=> string.Compare(Value, other.Value, StringComparison.Ordinal);
#endif

/// <summary>
/// Serves as a hash function for a <see cref="NameString"/> object.
Expand All @@ -141,9 +124,7 @@ public int CompareTo(NameString other)
/// algorithms and data structures such as a hash table.
/// </returns>
public override int GetHashCode()
{
return (HasValue ? StringComparer.Ordinal.GetHashCode(Value) : 0);
}
=> HasValue ? StringComparer.Ordinal.GetHashCode(Value) : 0;

/// <summary>
/// Operator call through to Equals
Expand All @@ -154,9 +135,7 @@ public override int GetHashCode()
/// <c>true</c> if both <see cref="NameString"/> values are equal.
/// </returns>
public static bool operator ==(NameString left, NameString right)
{
return left.Equals(right);
}
=> left.Equals(right);

/// <summary>
/// Operator call through to Equals
Expand All @@ -167,35 +146,29 @@ public override int GetHashCode()
/// <c>true</c> if both <see cref="NameString"/> values are not equal.
/// </returns>
public static bool operator !=(NameString left, NameString right)
{
return !left.Equals(right);
}
=> !left.Equals(right);

/// <summary>
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>The ToString combination of both values</returns>
public static string operator +(string left, NameString right)
{
// This overload exists to prevent the implicit string<->NameString
// converter from trying to call the NameString+NameString operator
// for things that are not name strings.
return string.Concat(left, right.ToString());
}
=> string.Concat(left, right.Value);

/// <summary>
/// </summary>
/// <param name="left">The left parameter</param>
/// <param name="right">The right parameter</param>
/// <returns>The ToString combination of both values</returns>
public static string operator +(NameString left, string right)
{
// This overload exists to prevent the implicit string<->NameString
// converter from trying to call the NameString+NameString operator
// for things that are not name strings.
return string.Concat(left.ToString(), right);
}
=> string.Concat(left.Value, right);

/// <summary>
/// Operator call through to Add
Expand All @@ -206,9 +179,7 @@ public override int GetHashCode()
/// The <see cref="NameString"/> combination of both values
/// </returns>
public static NameString operator +(NameString left, NameString right)
{
return left.Add(right);
}
=> left.Add(right);

/// <summary>
/// Implicitly creates a new <see cref="NameString"/> from
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
using System;
using System.Buffers;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Execution.Serialization;
using static HotChocolate.Execution.Properties.Resources;

namespace HotChocolate;

public static class ExecutionResultExtensions
{
private static readonly JsonQueryResultSerializer _serializer = new(false);
private static readonly JsonArrayResponseStreamSerializer _streamSerializer = new();
private static readonly JsonQueryResultSerializer _serializerIndented = new(true);

public static string ToJson(
this IExecutionResult result,
public static void WriteTo(
this IQueryResult result,
IBufferWriter<byte> writer,
bool withIndentations = true)
{
if (result is null)
{
throw new ArgumentNullException(nameof(result));
}

if (result is IReadOnlyQueryResult queryResult)
if (writer is null)
{
if (withIndentations)
{
return _serializerIndented.Serialize(queryResult);
}
return _serializer.Serialize(queryResult);
throw new ArgumentNullException(nameof(writer));
}

// TODO : resources / throw helper
throw new NotSupportedException(
"Only query results are supported.");
if (withIndentations)
{
_serializerIndented.Serialize(result, writer);
}
else
{
_serializer.Serialize(result, writer);
}
}

public static async ValueTask<string> ToJsonAsync(
public static string ToJson(
this IExecutionResult result,
bool withIndentations = true)
{
Expand All @@ -47,27 +50,11 @@ public static async ValueTask<string> ToJsonAsync(

if (result is IReadOnlyQueryResult queryResult)
{
if (withIndentations)
{
return _serializerIndented.Serialize(queryResult);
}
return _serializer.Serialize(queryResult);
}

if (result is IResponseStream responseStream)
{
// TODO : lets rework the serializer to align it with the query result serializer
using (var stream = new MemoryStream())
{
await _streamSerializer
.SerializeAsync(responseStream, stream)
.ConfigureAwait(false);
return Encoding.UTF8.GetString(stream.ToArray());
}
return withIndentations
? _serializerIndented.Serialize(queryResult)
: _serializer.Serialize(queryResult);
}

// TODO : resources / throw helper
throw new NotSupportedException(
"Only query results are supported.");
throw new NotSupportedException(ExecutionResultExtensions_OnlyQueryResults);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<InternalsVisibleTo Include="HotChocolate.Types.Mutations" />
<InternalsVisibleTo Include="HotChocolate.AspNetCore.Tests" />
<InternalsVisibleTo Include="StrawberryShake.CodeGeneration" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ VariableNode variable
return null;
}

private static DirectiveNode? GetDeferDirective(
internal static DirectiveNode? GetDeferDirective(
this IReadOnlyList<DirectiveNode> directives) =>
GetDirective(directives, WellKnownDirectives.Defer);

private static DirectiveNode? GetStreamDirective(
internal static DirectiveNode? GetStreamDirective(
this IReadOnlyList<DirectiveNode> directives) =>
GetDirective(directives, WellKnownDirectives.Stream);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Resolvers;

namespace HotChocolate.Execution.Processing;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/HotChocolate/Core/src/Execution/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@
<data name="ThrowHelper_ResolverContext_CannotCastParent" xml:space="preserve">
<value>The resolver parent type of field `{0}` is `{1}` but the resolver requested the type `{2}`. The resolver was unable to cast the parent type to the requested type.</value>
</data>
<data name="ExecutionResultExtensions_OnlyQueryResults" xml:space="preserve">
<value>Only query results are supported.</value>
</data>
</root>
Loading