Example #1
0
        private async Task <int> UpdateSingleSchemaAsync(
            UpdateCommandContext context,
            string path,
            CancellationToken cancellationToken)
        {
            Configuration?configuration =
                await ConfigurationStore.TryLoadAsync(path)
                .ConfigureAwait(false);

            if (configuration is { } &&
 private async Task <int> FindAndUpdateSchemasAsync(UpdateCommandContext context)
 {
     foreach (string path in FileSystem.GetClientDirectories(FileSystem.CurrentDirectory))
     {
         try
         {
             await UpdateSingleSchemaAsync(context, path);
         }
         catch
         {
             return(1);
         }
     }
     return(0);
 }
        public override Task <int> ExecuteAsync(
            UpdateCommandArguments arguments,
            CancellationToken cancellationToken)
        {
            using IDisposable command = Output.WriteCommand();

            var context = new UpdateCommandContext(
                arguments.Uri.HasValue() ? new Uri(arguments.Uri.Value()?.Trim()) : null,
                arguments.Path.Value()?.Trim(),
                arguments.Token.Value()?.Trim(),
                arguments.Scheme.Value()?.Trim() ?? "bearer");

            return(context.Path is null
                ? FindAndUpdateSchemasAsync(context)
                : UpdateSingleSchemaAsync(context, context.Path));
        }
        private async Task <bool> DownloadSchemaAsync(
            UpdateCommandContext context,
            Uri serviceUri,
            string schemaFilePath,
            CancellationToken cancellationToken)
        {
            using IActivity activity = Output.WriteActivity("Download schema");

            HttpClient client = HttpClientFactory.Create(
                context.Uri ?? serviceUri,
                context.Token,
                context.Scheme);

            return(await IntrospectionHelper.DownloadSchemaAsync(
                       client, FileSystem, activity, schemaFilePath,
                       cancellationToken)
                   .ConfigureAwait(false));
        }
Example #5
0
 private async Task <int> FindAndUpdateSchemasAsync(
     UpdateCommandContext context,
     CancellationToken cancellationToken)
 {
     foreach (string path in FileSystem.GetClientDirectories(FileSystem.CurrentDirectory))
     {
         try
         {
             await UpdateSingleSchemaAsync(
                 context, path, cancellationToken)
             .ConfigureAwait(false);
         }
         catch
         {
             return(1);
         }
     }
     return(0);
 }
Example #6
0
        private async Task <int> UpdateSingleSchemaAsync(
            UpdateCommandContext context,
            string clientDirectory,
            CancellationToken cancellationToken)
        {
            string configFilePath = Path.Combine(clientDirectory, WellKnownFiles.Config);
            var    buffer         = await FileSystem.ReadAllBytesAsync(configFilePath).ConfigureAwait(false);

            GraphQLConfig configuration = JsonSerializer.Deserialize <GraphQLConfig>(buffer);

            if (configuration is not null &&
                await UpdateSchemaAsync(context, clientDirectory, configuration, cancellationToken)
                .ConfigureAwait(false))
            {
                return(0);
            }

            return(1);
        }
        private async Task <int> FindAndUpdateSchemasAsync(
            UpdateCommandContext context,
            CancellationToken cancellationToken)
        {
            foreach (string path in FileSystem.GetClientDirectories(FileSystem.CurrentDirectory))
            {
                try
                {
                    await UpdateSingleSchemaAsync(
                        context, path, cancellationToken)
                    .ConfigureAwait(false);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch
                {
                    return(1);
                }
#pragma warning restore CA1031 // Do not catch general exception types
            }
            return(0);
        }
        private async Task <bool> UpdateSchemaAsync(
            UpdateCommandContext context,
            string clientDirectory,
            GraphQLConfig configuration,
            CancellationToken cancellationToken)
        {
            var hasErrors = false;

            if (configuration.Extensions.StrawberryShake.Url is not null)
            {
                var uri            = new Uri(configuration.Extensions.StrawberryShake.Url);
                var schemaFilePath = Path.Combine(clientDirectory, configuration.Schema);

                if (!await DownloadSchemaAsync(context, uri, schemaFilePath, cancellationToken)
                    .ConfigureAwait(false))
                {
                    hasErrors = true;
                }
            }

            return(!hasErrors);
        }
        public override async Task <int> ExecuteAsync(
            UpdateCommandArguments arguments,
            CancellationToken cancellationToken)
        {
            using IDisposable command = Output.WriteCommand();

            AccessToken?accessToken =
                await arguments.AuthArguments
                .RequestTokenAsync(Output, cancellationToken)
                .ConfigureAwait(false);

            var context = new UpdateCommandContext(
                arguments.Uri.HasValue() ? new Uri(arguments.Uri.Value()?.Trim()) : null,
                FileSystem.ResolvePath(arguments.Path.Value()?.Trim()),
                accessToken?.Token,
                accessToken?.Scheme);

            return(context.Path is null
                ? await FindAndUpdateSchemasAsync(context, cancellationToken)
                   .ConfigureAwait(false)
                : await UpdateSingleSchemaAsync(context, context.Path, cancellationToken)
                   .ConfigureAwait(false));
        }
        private async Task <int> UpdateSingleSchemaAsync(UpdateCommandContext context, string path)
        {
            Configuration?configuration = await ConfigurationStore.TryLoadAsync(context.Path !);

            if (configuration is { } &&