Skip to content

Commit

Permalink
fix: simplify branching logic when applying fed directives (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc committed Oct 12, 2023
1 parent 7b30f95 commit 6ef10cd
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/Federation/FederationTypeInterceptor.cs
Expand Up @@ -243,24 +243,24 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
{
descriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
descriptor.ApolloTag(casted.Name);
}
}

foreach (EnumValueDefinition enumValueDefinition in enumTypeDefinition.Values)
{
var enumValueDescriptor = EnumValueDescriptor.From(_context, enumValueDefinition);
if (enumValueDefinition.Member != null)
{
var enumValueDescriptor = EnumValueDescriptor.From(_context, enumValueDefinition);
foreach (var attribute in enumValueDefinition.Member.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
{
enumValueDescriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
enumValueDescriptor.ApolloTag(casted.Name);
}
Expand All @@ -272,14 +272,13 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
case InterfaceTypeDefinition interfaceTypeDefinition:
{
var descriptor = InterfaceTypeDescriptor.From(_context, interfaceTypeDefinition);

foreach (var attribute in interfaceTypeDefinition.RuntimeType.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
{
descriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
descriptor.ApolloTag(casted.Name);
}
Expand All @@ -295,7 +294,7 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
{
fieldDescriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
fieldDescriptor.ApolloTag(casted.Name);
}
Expand All @@ -313,24 +312,24 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
{
descriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
descriptor.ApolloTag(casted.Name);
}

}
foreach (InputFieldDefinition fieldDefinition in inputObjectTypeDefinition.Fields)
{
var fieldDescriptor = InputFieldDescriptor.From(_context, fieldDefinition);
if (fieldDefinition.RuntimeType != null)
{
var fieldDescriptor = InputFieldDescriptor.From(_context, fieldDefinition);
foreach (var attribute in fieldDefinition.RuntimeType.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
{
fieldDescriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
fieldDescriptor.ApolloTag(casted.Name);
}
Expand All @@ -342,40 +341,53 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
case ObjectTypeDefinition objectTypeDefinition:
{
var descriptor = ObjectTypeDescriptor.From(_context, objectTypeDefinition);

foreach (var attribute in objectTypeDefinition.RuntimeType.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
{
descriptor.Inaccessible();
}
if (attribute is ShareableAttribute)
switch (attribute)
{
descriptor.Shareable();
}
if (attribute is ApolloTagAttribute casted)
{
descriptor.ApolloTag(casted.Name);
case ApolloTagAttribute tag:
{
descriptor.ApolloTag(tag.Name);
break;
}
case InaccessibleAttribute:
{
descriptor.Inaccessible();
break;
}
case ShareableAttribute:
{
descriptor.Shareable();
break;
}
default: break;
}
}
foreach (ObjectFieldDefinition fieldDefinition in objectTypeDefinition.Fields)
{
var fieldDescriptor = ObjectFieldDescriptor.From(_context, fieldDefinition);
if (fieldDefinition.Member != null)
{
var fieldDescriptor = ObjectFieldDescriptor.From(_context, fieldDefinition);
foreach (var attribute in fieldDefinition.Member.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
switch (attribute)
{
fieldDescriptor.Inaccessible();
}
if (attribute is ShareableAttribute)
{
fieldDescriptor.Shareable();
}
if (attribute is ApolloTagAttribute casted)
{
fieldDescriptor.ApolloTag(casted.Name);
case ApolloTagAttribute tag:
{
fieldDescriptor.ApolloTag(tag.Name);
break;
}
case InaccessibleAttribute:
{
fieldDescriptor.Inaccessible();
break;
}
case ShareableAttribute:
{
fieldDescriptor.Shareable();
break;
}
default: break;
}
}
}
Expand All @@ -385,14 +397,13 @@ private void AddFederationDirectiveMarkers(DefinitionBase? definition)
case UnionTypeDefinition unionTypeDefinition:
{
var descriptor = UnionTypeDescriptor.From(_context, unionTypeDefinition);

foreach (var attribute in unionTypeDefinition.RuntimeType.GetCustomAttributes(true))
{
if (attribute is InaccessibleAttribute)
{
descriptor.Inaccessible();
}
if (attribute is ApolloTagAttribute casted)
else if (attribute is ApolloTagAttribute casted)
{
descriptor.ApolloTag(casted.Name);
}
Expand Down

0 comments on commit 6ef10cd

Please sign in to comment.