GraphQL: Link interface with circuit termination #5322

Closed
opened 2025-12-29 19:26:37 +01:00 by adam · 3 comments
Owner

Originally created by @ggidofalvy-tc on GitHub (Sep 6, 2021).

NetBox version

v3.0.1

Feature type

Change to existing functionality

Proposed functionality

Right now, it's not possible to query the connected circuit termination of an interface directly through GraphQL.

There's already a separate feature request, #7125 , which proposes linking circuit terminations with circuits.

Use case

As a NetBox GraphQL API user, I'd like to be able to create a report by querying the API in which the following are listed:

  • For each interface of each device, the connected circuit termination (and by extension, the circuit itself)

Querying the regular NetBox API for this same task would be much more inefficient than performing the query through the GraphQL API, especially when the number of devices (and interfaces) is high.

The query would look something like this:

{
  devices {
     name
     interfaces {
       name
       connected_circuit_termination {
#         circuit {
#           cid
#           provider {
#             name
#           }
#        }
       }
     }
   }
}

Database changes

No response

External dependencies

No response

Originally created by @ggidofalvy-tc on GitHub (Sep 6, 2021). ### NetBox version v3.0.1 ### Feature type Change to existing functionality ### Proposed functionality Right now, it's not possible to query the connected circuit termination of an interface directly through GraphQL. There's already a separate feature request, #7125 , which proposes linking circuit terminations with circuits. ### Use case As a NetBox GraphQL API user, I'd like to be able to create a report by querying the API in which the following are listed: - For each interface of each device, the connected circuit termination (and by extension, the circuit itself) Querying the regular NetBox API for this same task would be much more inefficient than performing the query through the GraphQL API, especially when the number of devices (and interfaces) is high. The query would look something like this: ``` { devices { name interfaces { name connected_circuit_termination { # circuit { # cid # provider { # name # } # } } } } } ``` ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: needs ownerpending closure labels 2025-12-29 19:26:37 +01:00
adam closed this issue 2025-12-29 19:26:37 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 5, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Dec 5, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jan 4, 2022):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Jan 4, 2022): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Author
Owner

@k01ek commented on GitHub (Feb 10, 2022):

I also met this problem and found a simple solution.
You need to add the termination_a(b)_circuit field, similar to the already existing _termination_a(b)_device in CableType

`class CableType(PrimaryObjectType):

class Meta:
    model = models.Cable
    fields = '__all__'
    filterset_class = filtersets.CableFilterSet

termination_a_circuit = graphene.Field(CircuitTerminationType)
termination_b_circuit = graphene.Field(CircuitTerminationType)

def resolve_termination_a_circuit(self, info):
    if isinstance(self.termination_a, CircuitTermination):
        return self.termination_a
    return None

def resolve_termination_b_circuit(self, info):
    if isinstance(self.termination_b, CircuitTermination):
        return self.termination_b
    return None        

def resolve_type(self, info):
    return self.type or None

def resolve_length_unit(self, info):
    return self.length_unit or None`

Query:
{ cable(id: 1){ termination_a_circuit{ id circuit{ description } } _termination_a_device { id } } }
Response:
{ "data": { "cable": { "termination_a_circuit": { "id": "1", "circuit": { "description": "" } }, "_termination_a_device": null } } }

@k01ek commented on GitHub (Feb 10, 2022): I also met this problem and found a simple solution. You need to add the termination_a(b)_circuit field, similar to the already existing _termination_a(b)_device in CableType `class CableType(PrimaryObjectType): class Meta: model = models.Cable fields = '__all__' filterset_class = filtersets.CableFilterSet termination_a_circuit = graphene.Field(CircuitTerminationType) termination_b_circuit = graphene.Field(CircuitTerminationType) def resolve_termination_a_circuit(self, info): if isinstance(self.termination_a, CircuitTermination): return self.termination_a return None def resolve_termination_b_circuit(self, info): if isinstance(self.termination_b, CircuitTermination): return self.termination_b return None def resolve_type(self, info): return self.type or None def resolve_length_unit(self, info): return self.length_unit or None` Query: `{ cable(id: 1){ termination_a_circuit{ id circuit{ description } } _termination_a_device { id } } }` Response: `{ "data": { "cable": { "termination_a_circuit": { "id": "1", "circuit": { "description": "" } }, "_termination_a_device": null } } }`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5322