Skip to content

Commit

Permalink
Add configurable access for generated clients (ChilliCream#6374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando committed Aug 6, 2023
1 parent 388f5c9 commit c4c333d
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 5,268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private static IReadOnlyList<GeneratorResult> GenerateCSharpDocuments(
CSharpGeneratorSettings settings)
{
var generatorSettings = new CSharpSyntaxGeneratorSettings(
settings.AccessModifier,
settings.NoStore,
settings.InputRecords,
settings.EntityRecords,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class CSharpGeneratorSettings
/// The root namespace of the client.
/// </summary>
public string Namespace { get; set; } = "StrawberryShake.GraphQL";

/// <summary>
/// The access modifier of the client.
/// </summary>
public AccessModifier AccessModifier { get; set; } = AccessModifier.Internal;

/// <summary>
/// Defines if a schema needs to be fully valid.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using StrawberryShake.CodeGeneration.CSharp.Builders;
using StrawberryShake.CodeGeneration.Descriptors;
using StrawberryShake.CodeGeneration.Descriptors.Operations;
Expand All @@ -21,6 +22,7 @@ protected override void Generate(

var classBuilder = ClassBuilder
.New()
.SetAccessModifier(settings.AccessModifier)
.SetName(fileName)
.SetComment(descriptor.Documentation)
.AddImplements(descriptor.InterfaceType.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace StrawberryShake.CodeGeneration.CSharp.Builders;
namespace StrawberryShake.CodeGeneration;

public enum AccessModifier
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ public class CSharpSyntaxGeneratorSettings
/// Creates a new code generator settings instance.
/// </summary>
public CSharpSyntaxGeneratorSettings(
AccessModifier accessModifier,
bool noStore,
bool inputRecords,
bool entityRecords, bool razorComponents)
bool entityRecords,
bool razorComponents)
{
AccessModifier = accessModifier;
NoStore = noStore;
InputRecords = inputRecords;
EntityRecords = entityRecords;
RazorComponents = razorComponents;
}

/// <summary>
/// Generates the client with specified access modifier.
/// </summary>
public AccessModifier AccessModifier { get; }

/// <summary>
/// Generates the client without a store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static IReadOnlyList<IError> AssertError(params string[] fileNames)
new CSharpGeneratorSettings
{
Namespace = "Foo.Bar",
ClientName = "FooClient"
ClientName = "FooClient",
AccessModifier = AccessModifier.Public
})
.Result;

Expand Down Expand Up @@ -86,6 +87,7 @@ public static void AssertResult(
{
Namespace = settings.Namespace ?? "Foo.Bar",
ClientName = settings.ClientName ?? "FooClient",
AccessModifier = AccessModifier.Public,
StrictSchemaValidation = settings.StrictValidation,
RequestStrategy = settings.RequestStrategy,
TransportProfiles = settings.Profiles,
Expand Down
Loading

0 comments on commit c4c333d

Please sign in to comment.