Skip to content

Commit

Permalink
fixed issue with versions not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Mar 4, 2021
1 parent 750f142 commit 4c4c071
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
10 changes: 5 additions & 5 deletions Directory.Packages.support.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<PackageVersion Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" />
<PackageVersion Update="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.8" />
<PackageVersion Update="System.Net.Http.Json" Version="3.2.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="3.1.12" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="3.1.12" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="3.1.12" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="3.1.12" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="3.1.12" />
<PackageVersion Update="Microsoft.Extensions.Configuration" Version="3.1.12" />
<PackageVersion Update="Microsoft.Extensions.Hosting" Version="3.1.12" />
<PackageVersion Update="Microsoft.Extensions.Logging" Version="3.1.12" />
<PackageVersion Update="Microsoft.Extensions.DependencyInjection" Version="3.1.12" />
<PackageVersion Update="Microsoft.Extensions.Options" Version="3.1.12" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HotChocolate.Language;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,75 +12,77 @@ namespace Rocket.Surgery.LaunchPad.HotChocolate.Configuration
{
public class ConfigureRootTypeSchemaInterceptor : SchemaInterceptor
{
private readonly ILogger<ConfigureRootTypeSchemaInterceptor> _logger;
private readonly IConfigureGraphqlRootType[] _configureMutationTypes;
private readonly IConfigureGraphqlRootType[] _configureQueryTypes;
private readonly IConfigureGraphqlRootType[] _configureSubscriptionTypes;

public ConfigureRootTypeSchemaInterceptor(
ILogger<ConfigureRootTypeSchemaInterceptor> logger,
NameString? name,
IEnumerable<IConfigureGraphqlRootType> configureGraphqlRootTypes
)
{
var _configureGraphqlRootTypes = configureGraphqlRootTypes.ToArray();
_configureMutationTypes = _configureGraphqlRootTypes
_logger = logger;
var configureRootTypes = configureGraphqlRootTypes.ToArray();
_configureMutationTypes = configureRootTypes
.Where(z => z.OperationType == OperationType.Mutation)
.ToArray();

_configureQueryTypes = _configureGraphqlRootTypes
_configureQueryTypes = configureRootTypes
.Where(z => z.OperationType == OperationType.Query)
.ToArray();

_configureSubscriptionTypes = _configureGraphqlRootTypes
_configureSubscriptionTypes = configureRootTypes
.Where(z => z.OperationType == OperationType.Subscription)
.ToArray();
}

public override void OnBeforeCreate(IDescriptorContext context, ISchemaBuilder schemaBuilder)
{
ConfigureType(context, schemaBuilder, OperationType.Mutation, _configureMutationTypes);
ConfigureType(context, schemaBuilder, OperationType.Query, _configureQueryTypes);
ConfigureType(context, schemaBuilder, OperationType.Subscription, _configureSubscriptionTypes);
ConfigureType(context, schemaBuilder, OperationType.Mutation, _configureMutationTypes, _logger);
ConfigureType(context, schemaBuilder, OperationType.Query, _configureQueryTypes, _logger);
ConfigureType(context, schemaBuilder, OperationType.Subscription, _configureSubscriptionTypes, _logger);
}

private static void ConfigureType(
IDescriptorContext context,
ISchemaBuilder schemaBuilder,
OperationType operationType,
IEnumerable<IConfigureGraphqlRootType> actions
IEnumerable<IConfigureGraphqlRootType> actions,
ILogger<ConfigureRootTypeSchemaInterceptor> logger
)
{
// var descriptor = ObjectTypeDescriptor.FromSchemaType(context, typeof(ObjectType));
// descriptor.Name(operationType.ToString());
// foreach (var item in actions)
// {
// item(descriptor);
// }
//
// if (descriptor.CreateDefinition().Fields.Any())
// {
if (!actions.Any())
return;
schemaBuilder.AddRootType(
new ObjectType(
descriptor =>
{
descriptor.Name(operationType.ToString());
foreach (var item in actions
.Where(
z => z.SchemaName is null
|| (
context.ContextData.TryGetValue("SchemaName", out var name) && name is string ns && ns == z.SchemaName
)
)
)

try
{
schemaBuilder.AddRootType(
new ObjectType(
descriptor =>
{
item.Configure(descriptor);
descriptor.Name(operationType.ToString());
foreach (var item in actions
.Where(
z => z.SchemaName is null
|| (
context.ContextData.TryGetValue("SchemaName", out var name) && name is string ns && ns == z.SchemaName
)
)
)
{
item.Configure(descriptor);
}
}
}
),
operationType
);
// }
),
operationType
);
}
catch (ArgumentException e)
{
logger.LogWarning(e, "Unable to configure {OperationType}", operationType);
}
}
}
}

0 comments on commit 4c4c071

Please sign in to comment.