ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

CLI: Update schema with basic authorization? #4805

Closed dariusz-wozniak closed 2 years ago

dariusz-wozniak commented 2 years ago

Is there an existing issue for this?

Describe the bug

I have a Basic Authorization enabled for the GraphQL server. I'd like to update schema by running dotnet graphql update -u https://localhost:5001/graphql and:

1: If Authorization is DISABLED then I get schema updated (correct behaviour):

dotnet graphql update -u https://localhost:5001/graphql
Download schema started.
Download schema completed in 2020 ms

1: If Authorization is ENABLED then I get schema updated (incorrect behaviour):

dotnet graphql update -u https://localhost:5001/graphql
Download schema started.
error HTTP_ERROR: Response status code does not indicate success: 500 (Internal Server Error).

Code for the authorization:

services.AddGraphQLServer()
                    .AddAuthorization()
//...

Please allow to authorize CLI via Basic.

Steps to reproduce

  1. Run dotnet graphql update -u https://localhost:5001/graphql on server where Basic Auth is enabled.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.6.0

tobias-tengler commented 2 years ago

You can pass your authorization header as an argument:

dotnet graphql update -u https://localhost:5001/graphql -x Authorization="Basic xxx"

Reference

dariusz-wozniak commented 2 years ago

When I run dotnet graph --help, there is nothing about -x param:

λ dotnet graphql --help
The following commands are supported:

- Initialize project and download schema
  dotnet graphql init http://localhost
  dotnet graphql init {url} [-p|--Path] [-n|--clientName] [--token] [--scheme] [--tokenEndpoint] [--clientId] [--clientSecret] [--scope]

- Update local schema
  dotnet graphql update
  dotnet graphql update [-p|--Path] [-u|--uri] [--token] [--scheme] [--tokenEndpoint] [--clientId] [--clientSecret] [--scope]

- Download the schema as GraphQL SDL
  dotnet graphql download http://localhost
  dotnet graphql download {url} [-f|--FileName] [--token] [--scheme] [--tokenEndpoint] [--clientId] [--clientSecret] [--scope]

And, when I try to use the above command, I get:

λ dotnet graphql update -u https://localhost:5001/graphql -x Authorization="Basic xxx"
Specify --help for a list of available options and commands.
Unhandled exception. McMaster.Extensions.CommandLineUtils.UnrecognizedCommandParsingException: Unrecognized option '-x'
   at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.HandleUnexpectedArg(String argTypeName, String argValue)
   at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessOption(OptionArgument arg)
   at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext()
   at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process()
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse(String[] args)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at StrawberryShake.Tools.Program.<Main>(String[] args)

Might be I'm using an older version of the tool, @tobias-tengler? 🤔

λ dotnet tool list
Package Id                 Version      Commands            Manifest
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
strawberryshake.tools      11.3.7       dotnet-graphql      [...]\.config\dotnet-tools.json
tobias-tengler commented 2 years ago

Yes, the latest version should be 12.6.1

dariusz-wozniak commented 2 years ago

Yes, that resolved the issue, thank you 👏