Skip to content

Commit

Permalink
add typename for reliable object deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
loulecrivain committed Sep 17, 2024
1 parent 622225c commit 65c2641
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions cosmo/graphqlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ def query(self, query):
return r.json()

def get_data(self, device_config):
# TODO add typename everywhere so that the custom JSON parser
# can have JSONRPC2.0-style interface and no hazardous
# field-guessing for object types
query_template = Template(
"""
{
device_list(
name: $device_array,
) {
__typename
id
name
serial
Expand All @@ -42,15 +40,19 @@ def get_data(self, device_config):
slug
}
platform {
__typename
manufacturer {
__typename
slug
}
slug
}
primary_ip4 {
__typename
address
}
interfaces {
__typename
id
name
enabled
Expand All @@ -60,40 +62,53 @@ def get_data(self, device_config):
mac_address
description
vrf {
__typename
id
}
lag {
__typename
id
}
ip_addresses {
__typename
address
}
untagged_vlan {
__typename
id
name
vid
}
tagged_vlans {
__typename
id
name
vid
}
tags {
__typename
name
slug
}
parent {
__typename
id
}
connected_endpoints {
__typename
... on InterfaceType {
__typename
name
device {
__typename
primary_ip4 {
__typename
address
}
interfaces {
__typename
ip_addresses {
__typename
address
}
}
Expand All @@ -103,37 +118,47 @@ def get_data(self, device_config):
custom_fields
}
staticroute_set {
__typename
interface {
__typename
name
}
vrf {
__typename
name
}
prefix {
__typename
prefix
family {
__typename
value
}
}
next_hop {
__typename
address
}
metric
}
}
vrf_list {
__typename
id
name
description
rd
export_targets {
__typename
name
}
import_targets {
__typename
name
}
}
l2vpn_list {
__typename
id
name
type
Expand All @@ -146,18 +171,24 @@ def get_data(self, device_config):
id
}
... on InterfaceType {
__typename
id
device {
__typename
name
interfaces (type: "virtual") {
__typename
ip_addresses {
__typename
address
}
parent {
__typename
name
type
}
vrf {
__typename
id
}
}
Expand Down

0 comments on commit 65c2641

Please sign in to comment.