Skip to content

Commit

Permalink
Added Strawberry Shake Blazor Package (#5360)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Aug 30, 2022
1 parent 4e154dd commit ffccfd9
Show file tree
Hide file tree
Showing 81 changed files with 737 additions and 1,491 deletions.
1 change: 0 additions & 1 deletion .build/Build.Environment.cs
Expand Up @@ -15,7 +15,6 @@ partial class Build
AbsolutePath SonarSolutionFile => SourceDirectory / "Build.Sonar.sln";
AbsolutePath TestSolutionFile => TemporaryDirectory / "Build.Test.sln";
AbsolutePath PackSolutionFile => SourceDirectory / "Build.Pack.sln";
AbsolutePath SgSolutionFile => SourceDirectory / "StrawberryShake" / "SourceGenerator" / "StrawberryShake.SourceGenerator.sln";

AbsolutePath OutputDirectory => RootDirectory / "output";
AbsolutePath TestResultDirectory => OutputDirectory / "test-results";
Expand Down
26 changes: 2 additions & 24 deletions .build/Build.Publish.cs
Expand Up @@ -26,8 +26,7 @@ partial class Build
.Requires(() => Configuration.Equals(Release))
.Executes(() =>
{
var packages = PackageDirectory.GlobFiles("HotChocolate.*.nupkg")
.Concat(PackageDirectory.GlobFiles("GreenDonut.*.nupkg"));
var packages = PackageDirectory.GlobFiles("*.*.nupkg");
DotNetNuGetPush(
_ => _
Expand Down Expand Up @@ -66,26 +65,6 @@ partial class Build
DotNetRestore(c => c.SetProjectFile(PackSolutionFile));
DotNetBuild(c => c
.SetNoRestore(true)
.SetProjectFile(RootDirectory / "src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp.Server/StrawberryShake.CodeGeneration.CSharp.Server.csproj")
.SetOutputDirectory(RootDirectory / "src/StrawberryShake/Tooling/src/.server")
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));
DotNetBuild(c => c
.SetNoRestore(true)
.SetProjectFile(RootDirectory / "src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp.Server/StrawberryShake.CodeGeneration.CSharp.Server.csproj")
.SetOutputDirectory(RootDirectory / "src/StrawberryShake/SourceGenerator/src/.server")
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));
DotNetBuild(c => c
.SetNoRestore(true)
.SetProjectFile(PackSolutionFile)
Expand Down Expand Up @@ -124,8 +103,7 @@ partial class Build
.Requires(() => Configuration.Equals(Release))
.Executes(() =>
{
var packages = PackageDirectory.GlobFiles("HotChocolate.*.nupkg")
.Concat(PackageDirectory.GlobFiles("GreenDonut.*.nupkg"));
var packages = PackageDirectory.GlobFiles("*.*.nupkg");
DotNetNuGetPush(
_ => _
Expand Down
4 changes: 0 additions & 4 deletions .build/Build.Sonar.cs
Expand Up @@ -35,8 +35,6 @@ partial class Build
SonarScannerBegin(SonarBeginPrSettings);
BuildCodeGenServer();
DotNetBuild(SonarBuildAll);
try
Expand Down Expand Up @@ -65,8 +63,6 @@ partial class Build
SonarScannerBegin(SonarBeginFullSettings);
BuildCodeGenServer();
DotNetBuild(SonarBuildAll);
try
Expand Down
5 changes: 0 additions & 5 deletions .build/Build.Tests.2.cs
Expand Up @@ -87,17 +87,12 @@ partial class Build
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "StrawberryShake" / "CodeGeneration" / "StrawberryShake.CodeGeneration.sln"));

Target TestStrawberryShakeSourceGenerator => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunClientTests(SourceDirectory / "StrawberryShake" / "SourceGenerator" / "StrawberryShake.SourceGenerator.sln"));

Target TestStrawberryShakeTooling => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunClientTests(SourceDirectory / "StrawberryShake" / "Tooling" / "StrawberryShake.Tooling.sln"));

void RunClientTests(AbsolutePath solutionFile)
{
BuildCodeGenServer(true);
RunTests(solutionFile);
}

Expand Down
1 change: 0 additions & 1 deletion .build/Build.Tests.cs
Expand Up @@ -69,7 +69,6 @@ partial class Build
TestHotChocolateUtilities,
TestStrawberryShakeClient,
TestStrawberryShakeCodeGeneration,
TestStrawberryShakeSourceGenerator,
TestStrawberryShakeTooling);

Target Cover => _ => _
Expand Down
17 changes: 0 additions & 17 deletions .build/Build.cs
@@ -1,7 +1,6 @@
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
Expand Down Expand Up @@ -29,7 +28,6 @@ partial class Build : NukeBuild
{
DotNetBuildSonarSolution(AllSolutionFile);
DotNetRestore(c => c.SetProjectFile(AllSolutionFile));
BuildCodeGenServer();
});

Target Compile => _ => _
Expand Down Expand Up @@ -62,19 +60,4 @@ partial class Build : NukeBuild
DotNetBuildSonarSolution(AllSolutionFile);
DotNetRestore(c => c.SetProjectFile(AllSolutionFile));
});

void BuildCodeGenServer(bool restore = false)
{
DotNetBuild(c => c
.SetNoRestore(!restore)
.SetProjectFile(RootDirectory / "src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp.Server/StrawberryShake.CodeGeneration.CSharp.Server.csproj")
.SetOutputDirectory(RootDirectory / "src/StrawberryShake/Tooling/src/.server")
.SetConfiguration(Configuration));

DotNetBuild(c => c
.SetNoRestore(!restore)
.SetProjectFile(RootDirectory / "src/StrawberryShake/CodeGeneration/src/CodeGeneration.CSharp.Server/StrawberryShake.CodeGeneration.CSharp.Server.csproj")
.SetOutputDirectory(RootDirectory / "src/StrawberryShake/SourceGenerator/src/.server")
.SetConfiguration(Configuration));
}
}
2 changes: 1 addition & 1 deletion .build/Helpers.cs
Expand Up @@ -30,7 +30,7 @@ static class Helpers
Path.Combine("HotChocolate", "Spatial"),
Path.Combine("StrawberryShake", "Client"),
Path.Combine("StrawberryShake", "CodeGeneration"),
Path.Combine("StrawberryShake", "SourceGenerator"),
Path.Combine("StrawberryShake", "MetaPackages"),
Path.Combine("StrawberryShake", "Tooling"),
"CookieCrumble"
};
Expand Down
12 changes: 0 additions & 12 deletions .devops/azure-pipelines.release-hotchocolate.yml
Expand Up @@ -247,18 +247,6 @@ stages:
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestStrawberryShakeSourceGenerator
displayName: src/StrawberryShake/SourceGenerator
steps:
- task: CmdLine@2
displayName: "Run Tests"
inputs:
script: "./build.cmd TestStrawberryShakeSourceGenerator --skip --test-partition $(System.JobPositionInPhase)"
- task: PublishBuildArtifacts@1
displayName: "Upload Test Results"
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestStrawberryShakeTooling
displayName: src/StrawberryShake/Tooling
steps:
Expand Down
24 changes: 12 additions & 12 deletions .devops/azure-pipelines.test-pr-hotchocolate.yml
Expand Up @@ -133,6 +133,18 @@ stages:
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestHotChocolateFusion
displayName: src/HotChocolate/Fusion
steps:
- task: CmdLine@2
displayName: "Run Tests"
inputs:
script: "./build.cmd TestHotChocolateFusion --skip --test-partition $(System.JobPositionInPhase)"
- task: PublishBuildArtifacts@1
displayName: "Upload Test Results"
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestHotChocolateLanguage
displayName: src/HotChocolate/Language
steps:
Expand Down Expand Up @@ -241,18 +253,6 @@ stages:
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestStrawberryShakeSourceGenerator
displayName: src/StrawberryShake/SourceGenerator
steps:
- task: CmdLine@2
displayName: "Run Tests"
inputs:
script: "./build.cmd TestStrawberryShakeSourceGenerator --skip --test-partition $(System.JobPositionInPhase)"
- task: PublishBuildArtifacts@1
displayName: "Upload Test Results"
inputs:
artifactName: test-results
pathtoPublish: "output/test-results"
- job: TestStrawberryShakeTooling
displayName: src/StrawberryShake/Tooling
steps:
Expand Down
Expand Up @@ -3,6 +3,7 @@
using HotChocolate.Language;
using HotChocolate.Types;
using HotChocolate.Utilities;
using IHasDirectives = HotChocolate.Language.IHasDirectives;

namespace HotChocolate.Execution.Processing;

Expand Down Expand Up @@ -64,6 +65,10 @@ private static IValueNode GetIfArgumentValue(DirectiveNode directive)
this IReadOnlyList<DirectiveNode> directives) =>
GetDirective(directives, WellKnownDirectives.Include);

internal static DirectiveNode? GetDeferDirective(
this IHasDirectives container) =>
GetDirective(container.Directives, WellKnownDirectives.Defer);

internal static DeferDirective? GetDeferDirective(
this IReadOnlyList<DirectiveNode> directives,
IVariableValueCollection variables)
Expand Down
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\SourceGenerator\src\CodeGeneration.CSharp.Analyzers\StrawberryShake.CodeGeneration.CSharp.Analyzers.csproj" />
<ProjectReference Include="..\Core\StrawberryShake.Core.csproj" />
</ItemGroup>

Expand Down
23 changes: 12 additions & 11 deletions src/StrawberryShake/Client/src/Razor/UseQuery.cs
Expand Up @@ -8,7 +8,7 @@ namespace StrawberryShake.Razor;
public abstract class UseQuery<TResult> : ComponentBase, IDisposable where TResult : class
{
private IDisposable? _subscription;
private bool _isLoading = true;
private bool _isInitializing = true;
private bool _isErrorResult;
private bool _isSuccessResult;
private TResult? _result;
Expand All @@ -27,20 +27,21 @@ protected void Subscribe(IObservable<IOperationResult<TResult>> observable)
{
_subscription?.Dispose();

_subscription = observable.Subscribe(operationResult =>
{
_result = operationResult.Data;
_errors = operationResult.Errors;
_isErrorResult = operationResult.IsErrorResult();
_isSuccessResult = operationResult.IsSuccessResult();
_isLoading = false;
StateHasChanged();
});
_subscription = observable
.Subscribe(operationResult =>
{
_result = operationResult.Data;
_errors = operationResult.Errors;
_isErrorResult = operationResult.IsErrorResult();
_isSuccessResult = operationResult.IsSuccessResult();
_isInitializing = false;
StateHasChanged();
});
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
if (_isLoading && LoadingContent is not null)
if (_isInitializing && LoadingContent is not null)
{
builder.AddContent(0, LoadingContent);
}
Expand Down
78 changes: 78 additions & 0 deletions src/StrawberryShake/Client/src/Razor/UseSubscription.cs
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace StrawberryShake.Razor;

public abstract class UseSubscription<TResult> : ComponentBase, IDisposable where TResult : class
{
private IDisposable? _subscription;
private bool _isInitializing = true;
private bool _isErrorResult;
private bool _isSuccessResult;
private TResult? _result;
private IReadOnlyList<IClientError>? _errors;
private bool _disposed;

[Parameter] public RenderFragment<TResult>? ChildContent { get; set; }

[Parameter] public RenderFragment<IReadOnlyList<IClientError>>? ErrorContent { get; set; }

[Parameter] public RenderFragment? LoadingContent { get; set; }

protected void Subscribe(IObservable<IOperationResult<TResult>> observable)
{
_subscription?.Dispose();

_subscription = observable
.Subscribe(operationResult =>
{
_result = operationResult.Data;
_errors = operationResult.Errors;
_isErrorResult = operationResult.IsErrorResult();
_isSuccessResult = operationResult.IsSuccessResult();
_isInitializing = false;
StateHasChanged();
});
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
if (_isInitializing && LoadingContent is not null)
{
builder.AddContent(0, LoadingContent);
}

if (_isErrorResult)
{
builder.AddContent(0, ErrorContent, _errors!);
}

if (_isSuccessResult)
{
builder.AddContent(0, ChildContent, _result!);
}

base.BuildRenderTree(builder);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_subscription?.Dispose();
}

_disposed = true;
}
}
}

0 comments on commit ffccfd9

Please sign in to comment.