nautobot.apps.graphql
¶
GraphQL API for Nautobot.
nautobot.apps.graphql.BigInteger
¶
Bases: BigInt
For backwards compatibility only.
nautobot.apps.graphql.ContentTypeType
¶
Bases: OptimizedNautobotObjectType
Graphene-Django object type for ContentType records.
Needed because ContentType is a built-in model, not one that we own and can auto-generate types for.
nautobot.apps.graphql.OptimizedNautobotObjectType
¶
Bases: DjangoObjectType
get_node(info, id)
classmethod
¶
Override get_node to enforce object-level permissions.
We intentionally do NOT override get_queryset (see above), so permission enforcement for Relay-style node lookups and any plugin code that calls get_node() is handled here instead.
nautobot.apps.graphql.construct_resolver(model_name, resolver_type)
¶
Constructs a resolve_[cable_peer|connected_endpoint]_
The returned resolver enforces object-level view permissions on the peer object (see
permission_safe_resolver), so a peer the requesting user is not permitted to view is returned as null.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model to construct a resolver function for (e.g. CircuitTermination). |
required |
resolver_type
|
str
|
One of ['connected_endpoint', 'cable_peer'] |
required |
nautobot.apps.graphql.execute_query(query, variables=None, request=None, user=None)
¶
Execute a query from the ORM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
String with GraphQL query. |
required |
variables
|
dict
|
If the query has variables they need to be passed in as a dictionary. |
None
|
request
|
RequestFactory
|
Used to authenticate. |
None
|
user
|
User
|
Used to authenticate. |
None
|
Returns:
| Type | Description |
|---|---|
GraphQLDocument
|
Result for query |
nautobot.apps.graphql.execute_saved_query(saved_query_name, **kwargs)
¶
Execute saved query from the ORM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saved_query_name
|
str
|
Name of a saved GraphQL query. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
variables |
Optional[dict]
|
If the query has variables they need to be passed in as a dictionary. |
request |
Optional[RequestFactory]
|
Used to authenticate. |
user |
Optional[User]
|
Used to authenticate. |
Returns:
| Type | Description |
|---|---|
GraphQLDocument
|
Result for query |
nautobot.apps.graphql.filter_permitted_objects(info, value)
¶
Filter value down to the related object(s) the requesting user is permitted to view.
This is the shared primitive behind permission_safe_resolver. It handles the shapes a GraphQL resolver
typically returns:
None->None.- A single model instance -> the instance if permitted, else
None. - An iterable of model instances (queryset, list, ...) -> a list containing only the permitted instances.
Values that are not Nautobot model instances (or models without a restrict()-capable manager) pass
through unchanged. Permission checks reuse the per-request cache in get_permitted_pks, so this does not
add a query per object.
nautobot.apps.graphql.get_filtering_args_from_filterset(filterset_class)
¶
Generate a list of filter arguments from a filterset.
The FilterSet class will be instantiated before extracting the list of arguments to account for dynamic filters, inserted when the class is instantiated. (required for Custom Fields filters).
Filter fields that are inheriting from BooleanFilter and NumberFilter will be converted to their appropriate type, everything else will be of type String. if the filter field is a subclass of MultipleChoiceFilter, the argument will be converted as a list
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filterset_class
|
FilterSet
|
FilterSet class used to extract the argument |
required |
Returns:
| Type | Description |
|---|---|
dict[Argument]
|
Filter Arguments organized in a dictionary |
nautobot.apps.graphql.mark_permission_enforced(resolver)
¶
Flag resolver as enforcing object-level view permissions on the related object(s) it returns.
Set automatically by permission_safe_resolver / permission_safe_attribute_resolver and the
auto-generated Nautobot resolvers. Apply it directly to a hand-written resolver that enforces
permissions by some other means, so the coverage guard test recognizes it as safe.
nautobot.apps.graphql.permission_safe_attribute_resolver(attribute_name)
¶
Build a permission-enforcing resolver that returns getattr(root, attribute_name).
Convenience for GraphQL fields backed by a model property/attribute (rather than a filterset, FK, or
custom resolver), such as Device.all_interfaces. The attribute's value -- instance, iterable, or
None -- is filtered to the objects the requesting user may view (see permission_safe_resolver).
nautobot.apps.graphql.permission_safe_resolver(resolver)
¶
Decorator that enforces object-level view permissions on the related object(s) a resolver returns.
Wrap any custom GraphQL resolver that returns related object(s) not already covered by the
auto-generated resolvers (e.g. property-backed accessors such as Device.all_interfaces, or
cable/path peer lookups). The wrapped resolver's return value is passed through
filter_permitted_objects, so a non-viewable single object becomes null and non-viewable entries are
dropped from returned lists.
nautobot.apps.graphql.str_to_var_name(verbose_name)
¶
Convert a string to a variable compatible name.
Examples:
IP Addresses > ip_addresses