Skip to content

Commit

Permalink
Fixed Strawberry Shake Base64 serialization. (#3598)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Apr 26, 2021
1 parent 48570d7 commit 89a07cf
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public static void WriteValue(object? value, Utf8JsonWriter writer)

switch (value)
{
case byte[] b:
writer.WriteBase64StringValue(b);
break;

case IEnumerable<KeyValuePair<string, object?>> dict:
WriteDictionary(dict, writer);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private async Task<bool> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using StrawberryShake.Tools.Configuration;

namespace StrawberryShake.Tools
{
Expand All @@ -12,35 +13,19 @@ 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;
Token = token;
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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -96,19 +97,7 @@ private async Task<bool> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ namespace StrawberryShake.Tools.OAuth
{
public class AccessToken
{
public AccessToken(string token, string scheme)
public AccessToken(string token, string? scheme)
{
Token = token;
Scheme = scheme;
}

public string Token { get; }

public string Scheme { get; }
public string? Scheme { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ public AuthArguments(
CommandOption tokenEndpoint,
CommandOption clientId,
CommandOption clientSecret,
CommandOption scopes)
CommandOption scopes,
CommandOption noScheme)
{
Token = token;
Scheme = scheme;
TokenEndpoint = tokenEndpoint;
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; }
Expand All @@ -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())
Expand All @@ -57,7 +67,8 @@ public AuthArguments(
ClientId.Value()!.Trim(),
ClientSecret.Value()!.Trim(),
scopes,
cancellationToken);
cancellationToken)
.ConfigureAwait(false);
return new AccessToken(token, _defaultScheme);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 89a07cf

Please sign in to comment.