Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
fix(cleanup): remove logic for adding keys to fields (#3)
Browse files Browse the repository at this point in the history
`KeyAttribute` is now only applicable to object types and can no longer be applied on fields. This logic is no longer valid.
  • Loading branch information
dariuszkuc authored Oct 11, 2023
1 parent 53c2813 commit e17fb99
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions src/Federation/FederationTypeInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ApolloGraphQL.HotChocolate.Federation.Constants;
using ApolloGraphQL.HotChocolate.Federation.Descriptors;
Expand Down Expand Up @@ -61,11 +60,6 @@ public override void OnAfterInitialize(
AddToUnionIfHasTypeLevelKeyDirective(
objectType,
objectTypeDefinition);

AggregatePropertyLevelKeyDirectives(
objectType,
objectTypeDefinition,
discoveryContext);
}
}

Expand Down Expand Up @@ -222,52 +216,6 @@ private void AddToUnionIfHasTypeLevelKeyDirective(
}
}

private void AggregatePropertyLevelKeyDirectives(
ObjectType objectType,
ObjectTypeDefinition objectTypeDefinition,
ITypeDiscoveryContext discoveryContext)
{
// if we find key markers on our fields, we need to construct the key directive
// from the annotated fields.
if (objectTypeDefinition.Fields.Any(f => f.ContextData.ContainsKey(KeyMarker)))
{
IReadOnlyList<ObjectFieldDefinition> fields = objectTypeDefinition.Fields;
var fieldSet = new StringBuilder();

foreach (var fieldDefinition in fields)
{
if (fieldDefinition.ContextData.ContainsKey(KeyMarker))
{
if (fieldSet.Length > 0)
{
fieldSet.Append(' ');
}

fieldSet.Append(fieldDefinition.Name);
}
}

// add the key directive with the dynamically generated field set.
AddKeyDirective(objectTypeDefinition, fieldSet.ToString());

// register dependency to the key directive so that it is completed before
// we complete this type.
foreach (var directiveDefinition in objectTypeDefinition.Directives)
{
discoveryContext.Dependencies.Add(
new TypeDependency(
directiveDefinition.Type,
TypeDependencyFulfilled.Completed));

discoveryContext.Dependencies.Add(new(directiveDefinition.Type));
}

// since this type has now a key directive we also need to add this type to
// the _Entity union type.
_entityTypes.Add(objectType);
}
}

private void AddMemberTypesToTheEntityUnionType(
ITypeCompletionContext completionContext,
DefinitionBase? definition)
Expand All @@ -281,18 +229,4 @@ private void AddMemberTypesToTheEntityUnionType(
}
}
}

private static void AddKeyDirective(
ObjectTypeDefinition objectTypeDefinition,
string fieldSet)
{
var directiveNode = new DirectiveNode(
WellKnownTypeNames.Key,
new ArgumentNode(
WellKnownArgumentNames.Fields,
fieldSet));

objectTypeDefinition.Directives.Add(
new DirectiveDefinition(directiveNode));
}
}

0 comments on commit e17fb99

Please sign in to comment.