I built a HotChocolate service and a strawberry client according to the documentation on the chillcream website. Here is my client code:
namespace strawberry_shake_graphql_client
{
internal class Program
{
static IServiceCollection serviceCollection = new ServiceCollection();
static IServiceProvider serviceProvider;
static IStrawberryShakeGraphQLClient client;
static async Task Main(string[] args)
{
serviceCollection
.AddStrawberryShakeGraphQLClient(StrawberryShake.ExecutionStrategy.CacheAndNetwork)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("https://localhost:7148/graphql/"));
serviceProvider = serviceCollection.BuildServiceProvider();
client = serviceProvider.GetRequiredService<IStrawberryShakeGraphQLClient>();
while(Console.ReadLine() != string.Empty)
{
await GetBooks();
}
}
static async Task GetBooks()
{
IOperationResult<IGetbooksResult> result = await client.Getbooks.ExecuteAsync();
if (result.IsErrorResult())
{
Console.WriteLine("ExecuteAsync() failed!");
return;
}
foreach (var book in result.Data.BooksList)
{
Console.WriteLine(book.Title);
}
}
}
}
My goal is to have my client consume data from the HotChocolate service if the network connection is online and from the local store/repository if the network connection is offline.
According to this https://chillicream.com/docs/strawberryshake/v13/caching I expect my client to continue working normally and provide data from the local cache/repository when the HotChocolate service is stopped or not reachable.
Instead of providing data from the local cache I get an HttpRequestExeption when my client executes the GetBooks
query with an offline HotChocolate service.
Is the code example missing something? is my expectation wrong? Can someone provide my with sample code how to implement my client to work as expected above?
Best regards, Siraf