Enable plugins to extend the GraphQL API #5975

Closed
opened 2025-12-29 19:35:04 +01:00 by adam · 2 comments
Owner

Originally created by @jeremystretch on GitHub (Jan 20, 2022).

Originally assigned to: @Jenjen1324, @jeremystretch on GitHub.

NetBox version

v3.1.6

Feature type

New functionality

Proposed functionality

Provide a mechanism through which a NetBox plugin can extend the GraphQL API with its own query class(es). I don't have a strong opinion on the optimal way to achieve this, but it should be fairly straightforward.

Currently, the GraphQL schema is formed by combining the root query from each app within NetBox:

class Query(
    CircuitsQuery,
    DCIMQuery,
    ExtrasQuery,
    IPAMQuery,
    TenancyQuery,
    UsersQuery,
    VirtualizationQuery,
    WirelessQuery,
    graphene.ObjectType
):
    pass

schema = graphene.Schema(query=Query, auto_camelcase=False)

We can extend this approach to allow dynamic inclusions. Something like:

query_classes = [
    CircuitsQuery,
    DCIMQuery,
    ExtrasQuery,
    IPAMQuery,
    TenancyQuery,
    UsersQuery,
    VirtualizationQuery,
    WirelessQuery,
    *get_plugin_queries()
]

class Query(*query_classes, graphene.ObjectType):
    pass

schema = graphene.Schema(query=Query, auto_camelcase=False)

get_plugin_queries() above is just a placeholder function, but we can probably handle the registration of GraphQL queries the same way we do for template extensions and navigation menu items today (by designating a configurable path to a variable within the plugin which contains these components).

This was originally proposed by @Jenjen1324 in WG83333.

Use case

This enables plugins to extend NetBox's GraphQL API, e.g. to add their own models.

Database changes

No response

External dependencies

No response

Originally created by @jeremystretch on GitHub (Jan 20, 2022). Originally assigned to: @Jenjen1324, @jeremystretch on GitHub. ### NetBox version v3.1.6 ### Feature type New functionality ### Proposed functionality Provide a mechanism through which a NetBox plugin can extend the GraphQL API with its own query class(es). I don't have a strong opinion on the optimal way to achieve this, but it should be fairly straightforward. Currently, the GraphQL schema is formed by combining the root query from each app within NetBox: ```python class Query( CircuitsQuery, DCIMQuery, ExtrasQuery, IPAMQuery, TenancyQuery, UsersQuery, VirtualizationQuery, WirelessQuery, graphene.ObjectType ): pass schema = graphene.Schema(query=Query, auto_camelcase=False) ``` We can extend this approach to allow dynamic inclusions. Something like: ```python query_classes = [ CircuitsQuery, DCIMQuery, ExtrasQuery, IPAMQuery, TenancyQuery, UsersQuery, VirtualizationQuery, WirelessQuery, *get_plugin_queries() ] class Query(*query_classes, graphene.ObjectType): pass schema = graphene.Schema(query=Query, auto_camelcase=False) ``` `get_plugin_queries()` above is just a placeholder function, but we can probably handle the registration of GraphQL queries the same way we do for template extensions and navigation menu items today (by designating a configurable path to a variable within the plugin which contains these components). This was originally proposed by @Jenjen1324 in WG83333. ### Use case This enables plugins to extend NetBox's GraphQL API, e.g. to add their own models. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: featuretopic: plugins labels 2025-12-29 19:35:04 +01:00
adam closed this issue 2025-12-29 19:35:04 +01:00
Author
Owner

@Jenjen1324 commented on GitHub (Jan 20, 2022):

I'll gladly take the initiative on this. I should be able to start on this next week.

@Jenjen1324 commented on GitHub (Jan 20, 2022): I'll gladly take the initiative on this. I should be able to start on this next week.
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2022):

@Jenjen1324 have you been able to make any progress on this? If not, no worries; I'm happy to take it on myself.

@jeremystretch commented on GitHub (Jan 28, 2022): @Jenjen1324 have you been able to make any progress on this? If not, no worries; I'm happy to take it on myself.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5975