diff --git a/src/StrawberryShake/Client/src/Core/Json/JsonSerializationHelper.cs b/src/StrawberryShake/Client/src/Core/Json/JsonSerializationHelper.cs index 593a49e2747..bfe8e945848 100644 --- a/src/StrawberryShake/Client/src/Core/Json/JsonSerializationHelper.cs +++ b/src/StrawberryShake/Client/src/Core/Json/JsonSerializationHelper.cs @@ -28,6 +28,10 @@ public static void WriteValue(object? value, Utf8JsonWriter writer) switch (value) { + case byte[] b: + writer.WriteBase64StringValue(b); + break; + case IEnumerable> dict: WriteDictionary(dict, writer); break; diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultHttpClientFactory.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultHttpClientFactory.cs index acbf4922185..5af049a7f4d 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultHttpClientFactory.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultHttpClientFactory.cs @@ -21,7 +21,9 @@ public HttpClient Create(Uri uri, string? token, string? scheme) if (token is not null) { httpClient.DefaultRequestHeaders.Authorization = - new AuthenticationHeaderValue(scheme ?? "bearer", token); + scheme is null + ? new AuthenticationHeaderValue(token) + : new AuthenticationHeaderValue(scheme, token); } return httpClient; diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs index 5d4ea35b7d7..34d68419dd1 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs @@ -55,7 +55,7 @@ private async Task DownloadSchemaAsync( DownloadCommandContext context, CancellationToken cancellationToken) { - using var activity = Output.WriteActivity("Download schema"); + using IActivity activity = Output.WriteActivity("Download schema"); HttpClient client = HttpClientFactory.Create( context.Uri, context.Token, context.Scheme); diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandArguments.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandArguments.cs index 5f8434df67b..db49d16ee18 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandArguments.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandArguments.cs @@ -8,12 +8,12 @@ public class InitCommandArguments public InitCommandArguments( CommandArgument uri, CommandOption path, - CommandOption Name, + CommandOption name, AuthArguments authArguments) { Uri = uri; Path = path; - this.Name = Name; + Name = name; AuthArguments = authArguments; } diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandContext.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandContext.cs index 2b71c8fcdeb..d25a43eb6ff 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandContext.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandContext.cs @@ -1,4 +1,5 @@ using System; +using StrawberryShake.Tools.Configuration; namespace StrawberryShake.Tools { @@ -12,8 +13,8 @@ public InitCommandContext( string? scheme) { SchemaName = "Schema"; - SchemaFileName = "schema.graphql"; - SchemaExtensionFileName = "schema.extensions.graphql"; + SchemaFileName = FileNames.SchemaFile; + SchemaExtensionFileName = FileNames.SchemaExtensionFile; ClientName = name; Path = path; Uri = uri; @@ -21,26 +22,10 @@ public InitCommandContext( Scheme = scheme; } - public InitCommandContext( - string schemaName, - string path, - string? token, - string? scheme) - { - SchemaName = schemaName; - SchemaFileName = schemaName + ".graphql"; - SchemaExtensionFileName = schemaName + "extensions.graphql"; - ClientName = schemaName + "Client"; - Path = path; - Uri = null; - Token = token; - Scheme = scheme; - } - public string SchemaName { get; } public string SchemaFileName { get; } public string SchemaExtensionFileName { get; } - public string ConfigFileName { get; } = ".graphqlrc.json"; + public string ConfigFileName => FileNames.GraphQLConfigFile; public string ClientName { get; } public string Path { get; } public Uri? Uri { get; } diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs index 3187a9a3a13..4496f9b1f91 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/InitCommandHandler.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using StrawberryShake.Tools.Configuration; using StrawberryShake.Tools.OAuth; +using static StrawberryShake.Tools.Configuration.FileContents; namespace StrawberryShake.Tools { @@ -96,19 +97,7 @@ private async Task DownloadSchemaAsync( { await FileSystem.WriteTextAsync( schemaExtensionFilePath, - @"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"")") + SchemaExtensionFileContent) .ConfigureAwait(false); return true; } diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AccessToken.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AccessToken.cs index 03a683ac60a..454fb773e31 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AccessToken.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AccessToken.cs @@ -2,7 +2,7 @@ namespace StrawberryShake.Tools.OAuth { public class AccessToken { - public AccessToken(string token, string scheme) + public AccessToken(string token, string? scheme) { Token = token; Scheme = scheme; @@ -10,6 +10,6 @@ public AccessToken(string token, string scheme) public string Token { get; } - public string Scheme { get; } + public string? Scheme { get; } } } diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AuthArgumentsBase.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AuthArgumentsBase.cs index 76ccd8744d6..86b5ba5aa8c 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AuthArgumentsBase.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/AuthArgumentsBase.cs @@ -17,7 +17,8 @@ public AuthArguments( CommandOption tokenEndpoint, CommandOption clientId, CommandOption clientSecret, - CommandOption scopes) + CommandOption scopes, + CommandOption noScheme) { Token = token; Scheme = scheme; @@ -25,10 +26,12 @@ public AuthArguments( ClientId = clientId; ClientSecret = clientSecret; Scopes = scopes; + NoScheme = noScheme; } public CommandOption Token { get; } public CommandOption Scheme { get; } + public CommandOption NoScheme { get; } public CommandOption TokenEndpoint { get; } public CommandOption ClientId { get; } public CommandOption ClientSecret { get; } @@ -40,9 +43,16 @@ public AuthArguments( { if (Token.HasValue()) { + string? scheme = null; + + if (!NoScheme.HasValue()) + { + scheme = Scheme.HasValue() ? Scheme.Value()!.Trim() : _defaultScheme; + } + return new AccessToken( Token.Value()!.Trim(), - Scheme.HasValue() ? Scheme.Value()!.Trim() : _defaultScheme); + scheme); } if (TokenEndpoint.HasValue() || ClientId.HasValue() || ClientSecret.HasValue()) @@ -57,7 +67,8 @@ public AuthArguments( ClientId.Value()!.Trim(), ClientSecret.Value()!.Trim(), scopes, - cancellationToken); + cancellationToken) + .ConfigureAwait(false); return new AccessToken(token, _defaultScheme); } diff --git a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/CommandLineApplicationExtensions.cs b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/CommandLineApplicationExtensions.cs index 9a2ba428d25..5cf1f2b1599 100644 --- a/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/CommandLineApplicationExtensions.cs +++ b/src/StrawberryShake/Tooling/src/dotnet-graphql/OAuth/CommandLineApplicationExtensions.cs @@ -38,13 +38,19 @@ public static AuthArguments AddAuthArguments( "The token scheme (default: bearer).", CommandOptionType.SingleValue); + CommandOption noScheme = app.Option( + "--no-scheme", + "The token will be send without a scheme.", + CommandOptionType.NoValue); + return new AuthArguments( token, scheme, tokenEndpoint, clientId, clientSecret, - scopes); + scopes, + noScheme); } } }