diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index 80c32e66d..6d93452cd 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -1,8 +1,11 @@ +import graphene + from dcim import filtersets, models from extras.graphql.mixins import ( ChangelogMixin, ConfigContextMixin, CustomFieldsMixin, ImageAttachmentsMixin, TagsMixin, ) from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin +from ipam.graphql.scalars import ASNField from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType __all__ = ( @@ -374,6 +377,7 @@ class RegionType(VLANGroupsMixin, OrganizationalObjectType): class SiteType(VLANGroupsMixin, ImageAttachmentsMixin, PrimaryObjectType): + asn = graphene.Field(ASNField) class Meta: model = models.Site diff --git a/netbox/ipam/graphql/scalars.py b/netbox/ipam/graphql/scalars.py new file mode 100644 index 000000000..d59375ba3 --- /dev/null +++ b/netbox/ipam/graphql/scalars.py @@ -0,0 +1,5 @@ +from netbox.graphql.scalars import BigInt + + +class ASNField(BigInt): + pass diff --git a/netbox/ipam/graphql/types.py b/netbox/ipam/graphql/types.py index 0fbe06c50..71c7fd24e 100644 --- a/netbox/ipam/graphql/types.py +++ b/netbox/ipam/graphql/types.py @@ -1,4 +1,7 @@ +import graphene + from ipam import filtersets, models +from ipam.graphql.scalars import ASNField from netbox.graphql.types import OrganizationalObjectType, PrimaryObjectType __all__ = ( @@ -18,6 +21,7 @@ __all__ = ( class ASNType(PrimaryObjectType): + asn = graphene.Field(ASNField) class Meta: model = models.ASN diff --git a/netbox/netbox/graphql/scalars.py b/netbox/netbox/graphql/scalars.py new file mode 100644 index 000000000..7d14189dd --- /dev/null +++ b/netbox/netbox/graphql/scalars.py @@ -0,0 +1,23 @@ +from graphene import Scalar +from graphql.language import ast +from graphql.type.scalars import MAX_INT, MIN_INT + + +class BigInt(Scalar): + """ + Handle any BigInts + """ + @staticmethod + def to_float(value): + num = int(value) + if num > MAX_INT or num < MIN_INT: + return float(num) + return num + + serialize = to_float + parse_value = to_float + + @staticmethod + def parse_literal(node): + if isinstance(node, ast.IntValue): + return BigInt.to_float(node.value)