GraphQL¶
            pynautobot.core.graphql
¶
    GraphQL endpoint for making queries to the Nautobot GraphQL endpoint.
            pynautobot.core.graphql.GraphQLException
¶
    
            pynautobot.core.graphql.GraphQLQuery
¶
    GraphQL Query class for making queries to the Nautobot GraphQL endpoint.
            __init__(api)
¶
    Initialization of class.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| api | api | pynatutobot Api class to make calls to the Nautobot API endpoints. | required | 
            query(query, variables=None)
¶
    Runs query against Nautobot Graphql endpoint.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| query | str | Query string to send to the API | required | 
| variables | dict | Dictionary of variables to use with the query string, defaults to None | None | 
Raises:
| Type | Description | 
|---|---|
| GraphQLException | 
 | 
| TypeError | 
 | 
| Exception | 
 | 
Examples:
>>> query = '''
... query {
...   sites {
...     id
...     name
...     region {
...       name
...     }
...   }
... }
... '''
>>> nautobot.graphql.query(query=query)
GraphQLRecord(json={'data': {'sites': [{'id': '2cfbc91e-361f-4129-9db6-bc21a6f88d38', 'name': 'ams', 'region': {'name': 'Netherlands'}}, {'id': '7ef021de-eb21-4403-8438-0e722c0f4b44', 'name': 'atl', 'region': {'name': 'United States'}}]}}, status_code=200)
>>> query = '''
... query {
...   sites (name: "den") {
...     id
...     name
...     region {
...       name
...     }
...   }
... }
... '''
>>> nautobot.graphql.query(query=query)
GraphQLRecord(json={'data': {'sites': [{'id': '45399b54-47f9-4eec-86e3-47352e103b1b', 'name': 'den', 'region': {'name': 'United States'}}]}}, status_code=200)
>>> variables = {"site_name": "den"}
>>> query = '''
... query ($site_name:String!) {
...   sites (name: $site_name) {
...     id
...     name
...     region {
...       name
...     }
...   }
... }
... '''
>>> nautobot.graphql.query(query=query, variables=variables)
GraphQLRecord(json={'data': {'sites': [{'id': '45399b54-47f9-4eec-86e3-47352e103b1b', 'name': 'den', 'region': {'name': 'United States'}}]}}, status_code=200)
Returns:
| Name | Type | Description | 
|---|---|---|
| GraphQLRecord | GraphQLRecord | Response of the API call | 
            pynautobot.core.graphql.GraphQLRecord
¶
    GraphQL Record class for handling the response from the GraphQL endpoint.
            __init__(json, status_code)
¶
    Initialization of class.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| json | dict | The json response from making a graphql query. | required | 
| status_code | int | The HTTP status code from making the graphql query. | required | 
            __repr__()
¶
    Return the representation of the GraphQLRecord object.
            __str__()
¶
    Return the string representation of the GraphQLRecord object.