Skip to content

Commit

Permalink
15809 Mark unions as nullable in GraphQL where appropriate (#15824)
Browse files Browse the repository at this point in the history
* 15809 mark unions as nullable where appropriate

* 15809 fix tests

* 15809 fix tests
  • Loading branch information
arthanson authored Apr 25, 2024
1 parent e05ca71 commit ded2fe9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions netbox/dcim/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class CableTerminationType(NetBoxObjectType):
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("CableTerminationTerminationType")]
], strawberry.union("CableTerminationTerminationType")] | None


@strawberry_django.type(
Expand Down Expand Up @@ -302,7 +302,7 @@ def parent(self) -> Annotated["InventoryItemTemplateType", strawberry.lazy('dcim
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("InventoryItemTemplateComponentType")]
], strawberry.union("InventoryItemTemplateComponentType")] | None


@strawberry_django.type(
Expand Down Expand Up @@ -431,7 +431,7 @@ def parent(self) -> Annotated["InventoryItemType", strawberry.lazy('dcim.graphql
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("InventoryItemComponentType")]
], strawberry.union("InventoryItemComponentType")] | None


@strawberry_django.type(
Expand Down
4 changes: 2 additions & 2 deletions netbox/ipam/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def assigned_object(self) -> Annotated[Union[
Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')],
Annotated["FHRPGroupType", strawberry.lazy('ipam.graphql.types')],
Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')],
], strawberry.union("IPAddressAssignmentType")]:
], strawberry.union("IPAddressAssignmentType")] | None:
return self.assigned_object


Expand Down Expand Up @@ -261,7 +261,7 @@ def scope(self) -> Annotated[Union[
Annotated["RegionType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("VLANGroupScopeType")]:
], strawberry.union("VLANGroupScopeType")] | None:
return self.scope


Expand Down
3 changes: 3 additions & 0 deletions netbox/utilities/testing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ def _build_query(self, name, **filters):
elif type(field.type) is StrawberryUnion:
# this would require a fragment query
continue
elif type(field.type) is StrawberryOptional and type(field.type.of_type) is StrawberryUnion:
# this would require a fragment query
continue
elif type(field.type) is StrawberryOptional and type(field.type.of_type) is LazyType:
fields_string += f'{field.name} {{ id }}\n'
elif hasattr(field, 'is_relation') and field.is_relation:
Expand Down

0 comments on commit ded2fe9

Please sign in to comment.