Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Authorization/Authorization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.1.39" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Custom-Directives/Custom-Directives.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Custom-HttpProcessor/Custom-HttpProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions Custom-HttpProcessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

This example project shows how to override the default HTTP Processor to take control of the `HttpContext` and perform any custom processing that may be needed related to the request/response pipeline surrounding GraphQL ASP.NET.

_Project Type_: .NET 7.0

_Solution:_ `Custom-HttpProcessor.sln`
2 changes: 1 addition & 1 deletion File-Uploads/src/FileUploads.API/FileUploads.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" version="1.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.12" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion LoggingProvider/LoggingProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.4.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.4.2" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.4.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.AspNet" Version="1.3.0" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.3.0" />
<PackageReference Include="GraphQL.AspNet" Version="1.4.3" />
<PackageReference Include="GraphQL.AspNet.Subscriptions" Version="1.4.3" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Subscriptions-StrawberryShake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Strawberry Shake Client Demo
A demo project that uses Chilli Cream's .NET GraphQL client. This demo creates a subscription server that constantly emits the server's current time and a .NET client that can watch for said events and displays them to a console window.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"strawberryshake.tools": {
"version": "15.1.3",
"commands": [
"dotnet-graphql"
],
"rollForward": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"schema": "schema.graphql",
"documents": "**/*.graphql",
"extensions": {
"strawberryShake": {
"name": "TimeOfDayServer",
"url": "http://localhost:5000/graphql",
"records": {
"inputs": false,
"entities": false
},
"transportProfiles": [
{
"default": "Http",
"subscription": "WebSocket"
}
]
}
}
}
59 changes: 59 additions & 0 deletions Subscriptions-StrawberryShake/Strawberry-Shake-Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@


namespace GraphQL.AspNet.Examples.StrawberryShakeClient
{
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

internal class Program
{
static async Task Main(string[] args)
{
var services = new ServiceCollection();

// Add the graphql server
// this call is code generated by Strawberry shake, it does not exist in the project files
services.AddTimeOfDayServer()
.ConfigureHttpClient(client =>
{
client.BaseAddress = new Uri("http://localhost:5000/graphql");
})
.ConfigureWebSocketClient(client =>
{
client.Uri = new Uri("ws://localhost:5000/graphql");
});

var provider = services.BuildServiceProvider();

using var scope = provider.CreateScope();

var server = scope.ServiceProvider.GetService<TimeOfDayServer>();


// do a get request which won't return until the server is online
// this makes sure that if the server and client are started
// at the same time in this demo that hte client wont try to subscribe until
// the server is ready
var time = await server.GetCurrentTime.ExecuteAsync();
Console.WriteLine($"Client Started...{time.Data.CurrentTime}");

// subscribe to the server and print time events to the console
server.OnTimeChanged.Watch()
.Subscribe(result =>
{
var formattedTime = "-error-";
var time = result?.Data?.OnTimeChanged?.CurrentTime;
if (time is not null)
{
formattedTime = time;
}

Console.WriteLine($"Server Time: {time}");
});

Console.ReadKey();

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query GetCurrentTime{
currentTime
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
subscription OnTimeChanged{
onTimeChanged {
currentTime
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>GraphQL.AspNet.Examples.StrawberryShakeClient</RootNamespace>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<GraphQL Update="queries/Query-Time.graphql" Generator="MSBuild:GenerateGraphQLCode" />
<GraphQL Update="queries/Subscription-OnTimeChanged.graphql" Generator="MSBuild:GenerateGraphQLCode" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="StrawberryShake.Server" Version="15.1.3" />
<PackageReference Include="StrawberryShake.Transport.WebSockets" Version="15.1.3" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
scalar _KeyFieldSet

directive @key(fields: _KeyFieldSet!) on SCHEMA | OBJECT

directive @serializationType(name: String!) on SCALAR

directive @runtimeType(name: String!) on SCALAR

directive @enumValue(value: String!) on ENUM_VALUE

directive @rename(name: String!) on INPUT_FIELD_DEFINITION | INPUT_OBJECT | ENUM | ENUM_VALUE

extend schema @key(fields: "id")
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
schema {
query: Query
subscription: Subscription
}

"A time of day that does not include a date component."
scalar TimeOnly

type Query {
currentTime: TimeOnly!
}

type CurrentTimeEventData {
currentTime: TimeOnly!
}

type Subscription {
onTimeChanged: CurrentTimeEventData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace GraphQL.AspNet.Examples.StrawberryShakeServer.BackgroundServices
{
using System;
using System.Threading;
using System.Threading.Tasks;
using GraphQL.AspNet.Examples.StrawberryShakeServer.Controllers;
using GraphQL.AspNet.Examples.StrawberryShakeServer.Models;
using GraphQL.AspNet.Interfaces.Subscriptions;
using GraphQL.AspNet.Schemas;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

/// <summary>
/// A simple hosted service that runs in the background on the server continually rasing the time of
/// day each second as it changes.
/// </summary>
internal sealed class TimeEventPublisher : BackgroundService
{
private readonly ISubscriptionEventRouter _eventRouter;
private readonly ILogger<TimeEventPublisher> _logger;

public TimeEventPublisher(ISubscriptionEventRouter eventRouter, ILogger<TimeEventPublisher> logger)
{
_eventRouter = eventRouter;
_logger = logger;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger?.LogInformation("Time Publisher started.");
var currentTime = TimeOnly.FromTimeSpan(TimeSpan.FromSeconds(Math.Round(DateTime.UtcNow.TimeOfDay.TotalSeconds)));
while (!stoppingToken.IsCancellationRequested)
{
try
{
await Task.Delay(500, stoppingToken);
}
catch (TaskCanceledException)
{
break;
}

var now = TimeOnly.FromTimeSpan(TimeSpan.FromSeconds(Math.Round(DateTime.UtcNow.TimeOfDay.TotalSeconds)));
if (currentTime != now)
{
var eventData = new CurrentTimeEventData
{
CurrentTime = now,
};
RaisePublishedEvent(eventData, SubscriptionController.TIME_CHANGED_EVENT);
_logger.LogDebug($"Time Change Published: {now:HH:mm:ss}");
}

currentTime = now;
}
}

/// <summary>
/// When the time of day changes
/// </summary>
/// <param name="eventData">The data package to publish</param>
/// <param name="eventName">The name of the event to publish teh data package as</param>
private void RaisePublishedEvent(CurrentTimeEventData eventData, string eventName)
{
var subscriptionEvent = new GraphQL.AspNet.SubscriptionServer.SubscriptionEvent
{
Id = Guid.NewGuid().ToString(),
EventName = eventName,
Data = eventData,
SchemaTypeName = typeof(GraphSchema).AssemblyQualifiedName,
DataTypeName = typeof(CurrentTimeEventData).AssemblyQualifiedName,
};

_eventRouter?.RaisePublishedEvent(subscriptionEvent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GraphQL.AspNet.Examples.StrawberryShakeServer.Controllers
{
using System;
using GraphQL.AspNet.Attributes;
using GraphQL.AspNet.Controllers;

/// <summary>
/// A query controller allowing anyone to retrieve the current second value from the server.
/// </summary>
public class QueryController : GraphController
{
/// <summary>
/// Returns the current time on the server. Provides a nice, ever changing
/// value to see repeated in the demo client.
/// </summary>
[QueryRoot("CurrentTime", typeof(TimeOnly))]
public TimeOnly CurrentTime()
{
// round to the last second
return TimeOnly.FromTimeSpan(TimeSpan.FromSeconds(Math.Round(DateTime.UtcNow.TimeOfDay.TotalSeconds)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace GraphQL.AspNet.Examples.StrawberryShakeServer.Controllers
{
using GraphQL.AspNet.Attributes;
using GraphQL.AspNet.Controllers;
using GraphQL.AspNet.Examples.StrawberryShakeServer.Models;
using GraphQL.AspNet.Interfaces.Controllers;

/// <summary>
/// A simple controller that allows clients to subscribe and receive the current time
/// of the server.
/// </summary>
public class SubscriptionController : GraphController
{
public const string TIME_CHANGED_EVENT = "TIME_CHANGED";

/// <summary>
/// A subscription that relays the time value whenever its raised to the server.
/// </summary>
/// <param name="eventData">The data package raised with the event.</param>
/// <returns></returns>
[SubscriptionRoot("onTimeChanged", typeof(CurrentTimeEventData), EventName = TIME_CHANGED_EVENT)]
public IGraphActionResult OnTimeChanged(CurrentTimeEventData eventData)
{
// relay the event data to each connected client.
return this.Ok(eventData);
}
}
}
Loading