Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable plugins to extend the GraphQL API #8405

Closed
Tracked by #8333
jeremystretch opened this issue Jan 20, 2022 · 2 comments
Closed
Tracked by #8333

Enable plugins to extend the GraphQL API #8405

jeremystretch opened this issue Jan 20, 2022 · 2 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Milestone

Comments

@jeremystretch
Copy link
Member

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

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application status: under review Further discussion is needed to determine this issue's scope and/or implementation topic: plugins Relates to the plugins framework labels Jan 20, 2022
@Jenjen1324
Copy link

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

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Jan 20, 2022
@jeremystretch
Copy link
Member Author

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

@jeremystretch jeremystretch added this to the v3.2 milestone Feb 4, 2022
jeremystretch added a commit that referenced this issue Feb 7, 2022
@jeremystretch jeremystretch self-assigned this Feb 7, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants