Skip to content

Commit

Permalink
removed prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Dec 16, 2024
1 parent cf4be7e commit d346a40
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ public static class HotChocolateAzureBlobStoragePersistedOperationsRequestExecut
/// A factory that resolves the Azure Blob Container Client that
/// shall be used for persistence.
/// </param>
/// <param name="blobNamePrefix">This prefix string is prepended before the hash of the document.</param>
/// <param name="blobNameSuffix">This suffix is appended after the hash of the document.</param>
public static IRequestExecutorBuilder AddAzureBlobStorageOperationDocumentStorage(
this IRequestExecutorBuilder builder,
Func<IServiceProvider, BlobContainerClient> containerClientFactory,
string blobNamePrefix = "",
string blobNameSuffix = ".graphql")
Func<IServiceProvider, BlobContainerClient> containerClientFactory)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(containerClientFactory);
if(builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

if(containerClientFactory is null)
{
throw new ArgumentNullException(nameof(containerClientFactory));
}

return builder.ConfigureSchemaServices(
s => s.AddAzureBlobStorageOperationDocumentStorage(
sp => containerClientFactory(sp.GetCombinedServices()), blobNamePrefix, blobNameSuffix));
sp => containerClientFactory(sp.GetCombinedServices())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace HotChocolate;

/// <summary>
/// Provides utility methods to setup dependency injection.
/// Provides utility methods to set up dependency injection.
/// </summary>
public static class HotChocolateAzureBlobStoragePersistedOperationsServiceCollectionExtensions
{
Expand All @@ -20,22 +20,24 @@ public static class HotChocolateAzureBlobStoragePersistedOperationsServiceCollec
/// A factory that resolves the Azure Blob Container Client that
/// shall be used for persistence.
/// </param>
/// <param name="blobNamePrefix">This prefix string is prepended before the hash of the document.</param>
/// <param name="blobNameSuffix">This suffix is appended after the hash of the document.</param>
public static IServiceCollection AddAzureBlobStorageOperationDocumentStorage(
this IServiceCollection services,
Func<IServiceProvider, BlobContainerClient> containerClientFactory,
string blobNamePrefix = "",
string blobNameSuffix = ".graphql"
)
Func<IServiceProvider, BlobContainerClient> containerClientFactory)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(containerClientFactory);
if(services == null)
{
throw new ArgumentNullException(nameof(services));
}

if(containerClientFactory == null)
{
throw new ArgumentNullException(nameof(containerClientFactory));
}

return services
.RemoveService<IOperationDocumentStorage>()
.AddSingleton<IOperationDocumentStorage>(
sp => new AzureBlobOperationDocumentStorage(containerClientFactory(sp), blobNamePrefix, blobNameSuffix));
sp => new AzureBlobOperationDocumentStorage(containerClientFactory(sp)));
}

private static IServiceCollection RemoveService<TService>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace HotChocolate.PersistedOperations.AzureBlobStorage;
public class AzureBlobStorageOperationDocumentStorageTests : IClassFixture<AzureStorageBlobResource>
{
private readonly BlobContainerClient _client;
private const string Prefix = "hc_";
private const string Suffix = ".graphql";

public AzureBlobStorageOperationDocumentStorageTests(AzureStorageBlobResource blobStorageResource)
{
Expand All @@ -23,7 +21,7 @@ public async Task Write_OperationDocument_To_Storage()
{
// arrange
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);
var document = new OperationDocumentSourceText("{ foo }");

// act
Expand All @@ -41,21 +39,21 @@ public async Task Write_OperationDocument_documentId_Invalid()
{
// arrange
var documentId = new OperationDocumentId();
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);
var document = new OperationDocumentSourceText("{ foo }");

// act
async Task Action() => await storage.SaveAsync(documentId, document);

// assert
await Assert.ThrowsAsync<ArgumentNullException>(Action);
await Assert.ThrowsAsync<ArgumentException>(Action);
}

[Fact]
public async Task Write_OperationDocument_OperationDocument_Is_Null()
{
// arrange
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));

// act
Expand All @@ -70,7 +68,7 @@ public async Task Read_OperationDocument_From_Storage()
{
// arrange
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);
var buffer = "{ foo }"u8.ToArray();
await WriteBlob(documentId.Value, buffer);

Expand All @@ -89,7 +87,7 @@ public async Task Read_OperationDocument_documentId_Invalid()
{
// arrange
var documentId = new OperationDocumentId();
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);

// act
async Task Action() => await storage.TryReadAsync(documentId);
Expand All @@ -116,5 +114,5 @@ private async Task WriteBlob(string key, byte[] buffer)

private async Task DeleteBlob(string key) => await _client.DeleteBlobAsync(BlobName(key));

private static string BlobName(string key) => $"{Prefix}{key}{Suffix}";
private static string BlobName(string key) => $"{key}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace HotChocolate.PersistedOperations.AzureBlobStorage;

public class IntegrationTests : IClassFixture<AzureStorageBlobResource>
{
private const string Prefix = "hc_";
private const string Suffix = ".graphql";

private readonly BlobContainerClient _client;

public IntegrationTests(AzureStorageBlobResource blobStorageResource)
Expand All @@ -24,7 +21,7 @@ public async Task ExecutePersistedOperation()
{
// arrange
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);

await storage.SaveAsync(
documentId,
Expand All @@ -34,7 +31,7 @@ await storage.SaveAsync(
await new ServiceCollection()
.AddGraphQL()
.AddQueryType(c => c.Name("Query").Field("a").Resolve("b"))
.AddAzureBlobStorageOperationDocumentStorage(_ => _client, Prefix, Suffix)
.AddAzureBlobStorageOperationDocumentStorage(_ => _client)
.UseRequest(n => async c =>
{
await n(c);
Expand Down Expand Up @@ -62,14 +59,14 @@ public async Task ExecutePersistedOperation_NotFound()
{
// arrange
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));
var storage = new AzureBlobOperationDocumentStorage(_client, Prefix, Suffix);
var storage = new AzureBlobOperationDocumentStorage(_client);
await storage.SaveAsync(documentId, new OperationDocumentSourceText("{ __typename }"));

var executor =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType(c => c.Name("Query").Field("a").Resolve("b"))
.AddAzureBlobStorageOperationDocumentStorage(_ => _client, Prefix, Suffix)
.AddAzureBlobStorageOperationDocumentStorage(_ => _client)
.UseRequest(n => async c =>
{
await n(c);
Expand Down

0 comments on commit d346a40

Please sign in to comment.