@@ -438,44 +438,33 @@ public static async Task<CompositionResult<MutableSchemaDefinition>> ComposeAsyn
438
438
{
439
439
environment ??= Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ?? "Development" ;
440
440
441
- var sourceSchemas = await ReadSourceSchemasAsync ( sourceSchemaFiles , cancellationToken ) ;
442
- var schemaNames = new SortedSet < string > ( StringComparer . Ordinal ) ;
443
-
444
- await UpdateArchiveMetadata ( archive , schemaNames , cancellationToken ) ;
441
+ var sourceSchemas = await ReadSourceSchemasAsync (
442
+ sourceSchemaFiles ,
443
+ cancellationToken ) ;
445
444
446
- using var bufferWriter = new PooledArrayWriter ( ) ;
445
+ var sourceSchemaNamesInPackage = new SortedSet < string > (
446
+ await archive . GetSourceSchemaNamesAsync ( cancellationToken ) ,
447
+ StringComparer . Ordinal ) ;
447
448
448
- foreach ( var schemaName in schemaNames )
449
+ foreach ( var schemaName in sourceSchemaNamesInPackage )
449
450
{
450
- if ( ! sourceSchemas . ContainsKey ( schemaName ) )
451
+ if ( sourceSchemas . ContainsKey ( schemaName ) )
451
452
{
452
- var sourceSchemaConfiguration =
453
- await archive . TryGetSourceSchemaConfigurationAsync (
454
- schemaName ,
455
- cancellationToken ) ;
453
+ // We have a new configuration for the schema, so we'll take that
454
+ // instead of the one in the gateway package.
455
+ continue ;
456
+ }
456
457
457
- if ( sourceSchemaConfiguration is null )
458
- {
459
- continue ;
460
- }
458
+ var configuration = await archive . TryGetSourceSchemaConfigurationAsync ( schemaName , cancellationToken ) ;
461
459
462
- bufferWriter . Reset ( ) ;
460
+ if ( configuration is null )
461
+ {
462
+ continue ;
463
+ }
463
464
464
- await using ( var stream = await sourceSchemaConfiguration . OpenReadSchemaAsync ( cancellationToken ) )
465
- {
466
- int read ;
465
+ var sourceText = await ReadSchemaSourceTextAsync ( configuration , cancellationToken ) ;
467
466
468
- do
469
- {
470
- var memory = bufferWriter . GetMemory ( 4096 ) ;
471
- read = await stream . ReadAsync ( memory , cancellationToken ) ;
472
- bufferWriter . Advance ( read ) ;
473
- } while ( read > 0 ) ;
474
- }
475
-
476
- var sourceText = new SourceSchemaText ( schemaName , Encoding . UTF8 . GetString ( bufferWriter . WrittenSpan ) ) ;
477
- sourceSchemas [ schemaName ] = ( sourceText , sourceSchemaConfiguration . Settings ) ;
478
- }
467
+ sourceSchemas [ schemaName ] = ( new SourceSchemaText ( schemaName , sourceText ) , configuration . Settings ) ;
479
468
}
480
469
481
470
var schemaComposerOptions = new SchemaComposerOptions
@@ -495,12 +484,29 @@ await archive.TryGetSourceSchemaConfigurationAsync(
495
484
return result ;
496
485
}
497
486
498
- bufferWriter . Reset ( ) ;
487
+ using var bufferWriter = new PooledArrayWriter ( ) ;
499
488
new SettingsComposer ( ) . Compose (
500
489
bufferWriter ,
501
490
sourceSchemas . Values . Select ( t => t . Item2 . RootElement ) . ToArray ( ) ,
502
491
environment ) ;
503
492
493
+ var metadata = new ArchiveMetadata
494
+ {
495
+ SupportedGatewayFormats = [ new Version ( 2 , 0 , 0 ) ] ,
496
+ SourceSchemas = [ ..sourceSchemas . Keys ]
497
+ } ;
498
+
499
+ await archive . SetArchiveMetadataAsync ( metadata , cancellationToken ) ;
500
+
501
+ foreach ( var ( schemaName , ( schema , settings ) ) in sourceSchemas )
502
+ {
503
+ await archive . SetSourceSchemaConfigurationAsync (
504
+ schemaName ,
505
+ Encoding . UTF8 . GetBytes ( schema . SourceText ) ,
506
+ settings ,
507
+ cancellationToken ) ;
508
+ }
509
+
504
510
await archive . SetGatewayConfigurationAsync (
505
511
result . Value + Environment . NewLine ,
506
512
JsonDocument . Parse ( bufferWriter . WrittenMemory ) ,
@@ -512,30 +518,6 @@ await archive.SetGatewayConfigurationAsync(
512
518
return result ;
513
519
}
514
520
515
- private static async Task UpdateArchiveMetadata (
516
- FusionArchive archive ,
517
- SortedSet < string > sourceSchemaNames ,
518
- CancellationToken cancellationToken )
519
- {
520
- var metadata = await archive . GetArchiveMetadataAsync ( cancellationToken ) ;
521
-
522
- if ( metadata is not null )
523
- {
524
- foreach ( var schemaName in metadata . SourceSchemas )
525
- {
526
- sourceSchemaNames . Add ( schemaName ) ;
527
- }
528
- }
529
-
530
- metadata = new ArchiveMetadata
531
- {
532
- SupportedGatewayFormats = [ new Version ( 2 , 0 , 0 ) ] ,
533
- SourceSchemas = [ .. sourceSchemaNames ]
534
- } ;
535
-
536
- await archive . SetArchiveMetadataAsync ( metadata , cancellationToken ) ;
537
- }
538
-
539
521
public static void WriteCompositionLog (
540
522
CompositionLog compositionLog ,
541
523
IStandardStreamWriter writer ,
@@ -640,6 +622,15 @@ static async Task ReadSourceSchemaAsync(
640
622
}
641
623
}
642
624
625
+ private static async Task < string > ReadSchemaSourceTextAsync (
626
+ SourceSchemaConfiguration configuration ,
627
+ CancellationToken cancellationToken )
628
+ {
629
+ await using var stream = await configuration . OpenReadSchemaAsync ( cancellationToken ) ;
630
+ using var reader = new StreamReader ( stream , Encoding . UTF8 ) ;
631
+ return await reader . ReadToEndAsync ( cancellationToken ) ;
632
+ }
633
+
643
634
/// <summary>
644
635
/// Since we're prefixing the message with an emoji and space before printing,
645
636
/// we need to also indent each line of a multiline message by three spaces to fix the alignment.
0 commit comments