Skip to content

Enable plugins to extend the GraphQL API #8405

@jeremystretch

Description

@jeremystretch

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

Metadata

Metadata

Labels

status: acceptedThis issue has been accepted for implementationtopic: pluginsRelates to the plugins frameworktype: featureIntroduction of new functionality to the application

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions