GraphQL is a query language for APIs and has been adopted by popular web services, including GitHub, ArangoDB and Nautobot, a network automation platform. This session introduces GraphQL and demonstrates using Nautobot as a Source of Truth for managing the configuration of Arista Containerized EOS (cEOS) routers using Ansible.
Network engineers who wish to learn GraphQL for Nautobot, Ansible, and cEOS will benefit from this session. A sample code repository will be published for attendees.
2. Introduction to GraphQL for NetDevOps Engineers
Details
GraphQL is a query language for APIs and has been
adopted by popular web services, including GitHub,
ArangoDB and Nautobot, a network automation platform.
This session introduces GraphQL and demonstrates
using Nautobot as a Source of Truth for managing the
configuration of Arista Containerized EOS (cEOS) routers
using Ansible.
Network engineers who wish to learn GraphQL for
Nautobot, Ansible, and cEOS will benefit from this
session. A sample code repository will be published for
attendees.
Photo Credit: Dan Dimmock on Unsplash
3. What’s in it for me?
gitlab.com/joelwking/graphql4netdevops
Arista CloudEOS
Network to Code
Ansible
12. GraphQL vs APIs
• Supports Queries (via GET or POST)
modifying state in the server (mutation)
• HTTP via a single URL endpoint
• Returns the data that's explicitly requested
(avoiding versioning)
• Query fields are same as the results
(you get back what you expect)
• Arguments implement data transformations
e.g. height(unit: FOOT)
Supports all REST Verbs: POST PATCH GET …
HTTP suite of URLs for each resource
New features to an API = new version
Postman, Swagger | OpenAPI
Client-side data transformations
13. GraphQL
GraphQL is a query language for your API
{ API } { GraphQL } nautobot.query_graphql
Nautobot
16. arguments
{
"data": {
"devices": [
{
"name": "ceos1.example.net",
"interfaces": [
{
"mtu": 9214,
"name": "Ethernet1"
}
],
"tags": [
{
"name": "r00"
}
],
"device_role": {
"name": "LEAF"
}
}
]
}
}
GraphQL, every field and nested object can get its own set of arguments
RESULT
query ArgumentExample {
devices(name: "ceos1.example.net") {
name
interfaces(name: "Ethernet1") {
mtu
name
}
tags {
name
}
device_role{
name
}
}
}
17. graph Variables
factor dynamic values out of the query and pass them as a separate dictionary.
Eliminate any static value(s) in the
query with $variableName
Declare $variableName as one of the variables
accepted by the query
Pass variableName: value in the separate,
transport-specific (usually JSON) variables
dictionary
19. multiple GraphQL operations in a request
query MultipleQueries {
devices(name: "ceos1.example.net") {
name
interfaces(name: "Ethernet1") {
mtu
name
}
tags {
name
}
device_role{
name
}
}
device_roles {
name
color
description
}
}
{
"data": {
"devices": [
{
"name": "ceos1.example.net",
"interfaces": [
{
"mtu": 9214,
"name": "Ethernet1"
}
],
"tags": [
{
"name": "r00"
}
],
"device_role": {
"name": "LEAF"
}
}
],
"device_roles": [
{
"name": "LEAF",
"color": "ffeeff",
"description": ""
},
{
"name": "SPINE",
"color": "ffeeff",
"description": ""
},
20. - name: configure a device defined in Nautobot
hosts: '{{ group_name | default("cloud_ceos") }}'
gather_facts: false
vars:
graph_vars:
device_name: '{{ inventory_hostname }}'
tip
./configure_device.yml --limit ceos1.example.net
execute a GraphQL query per device at the beginning of the playbook
--limit ceos1.example.net,ceos2.example.net
Mutations can be used for adding data
Mutation queries modify data in the data store and returns a value. It can be used to insert, update, or delete data. Mutations are defined as a part of the schema.