Skip to content

Commit

Permalink
lldp layer demo fix (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
soson authored Feb 19, 2024
1 parent a1f6ffb commit 38e861c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
25 changes: 16 additions & 9 deletions src/helpers/topology.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,24 @@ export function makeTopologyNodes(dbDevices: PrismaDevice[], topologyDevices?: T
if (!topologyDevices) {
return [];
}
const nodes = dbDevices
.map((device) => {
const node = topologyDevices?.phyDevices.edges?.find((e) => e?.node?.name === device.name)?.node;
if (node != null) {

// hashmap used to map topology device with device inventory id via its name
const dbDevicesMap = new Map(dbDevices.map((d) => [d.name, d]));

const nodes =
topologyDevices.phyDevices.edges
?.map((edge) => {
if (!edge || !edge.node) {
return null;
}
const { node } = edge;

return {
id: toGraphId('GraphNode', node.id),
name: node.name,
deviceType: node.details.device_type ?? null,
softwareVersion: node.details.sw_version ?? null,
device,
device: dbDevicesMap.get(node.name) ?? null,
interfaces:
node.phyInterfaces.edges?.map((e) => ({
id: unwrap(e?.node?.id),
Expand All @@ -251,10 +260,8 @@ export function makeTopologyNodes(dbDevices: PrismaDevice[], topologyDevices?: T
})) ?? [],
coordinates: node.coordinates,
};
}
return null;
})
.filter(omitNullValue);
})
.filter(omitNullValue) ?? [];
return nodes;
}

Expand Down
3 changes: 2 additions & 1 deletion src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ enum GraphEdgeStatus {

type GraphNode implements BaseGraphNode {
coordinates: GraphNodeCoordinates!
device: Device!
device: Device
deviceType: String
id: ID!
interfaces: [GraphNodeInterface!]!
name: String!
softwareVersion: String
}

Expand Down
7 changes: 5 additions & 2 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,11 @@ export interface NexusGenObjects {
GraphNode: {
// root type
coordinates: NexusGenRootTypes['GraphNodeCoordinates']; // GraphNodeCoordinates!
device: NexusGenRootTypes['Device']; // Device!
device?: NexusGenRootTypes['Device'] | null; // Device
deviceType?: string | null; // String
id: string; // ID!
interfaces: NexusGenRootTypes['GraphNodeInterface'][]; // [GraphNodeInterface!]!
name: string; // String!
softwareVersion?: string | null; // String
};
GraphNodeCoordinates: {
Expand Down Expand Up @@ -797,10 +798,11 @@ export interface NexusGenFieldTypes {
GraphNode: {
// field return type
coordinates: NexusGenRootTypes['GraphNodeCoordinates']; // GraphNodeCoordinates!
device: NexusGenRootTypes['Device']; // Device!
device: NexusGenRootTypes['Device'] | null; // Device
deviceType: string | null; // String
id: string; // ID!
interfaces: NexusGenRootTypes['GraphNodeInterface'][]; // [GraphNodeInterface!]!
name: string; // String!
softwareVersion: string | null; // String
};
GraphNodeCoordinates: {
Expand Down Expand Up @@ -1337,6 +1339,7 @@ export interface NexusGenFieldTypeNames {
deviceType: 'String';
id: 'ID';
interfaces: 'GraphNodeInterface';
name: 'String';
softwareVersion: 'String';
};
GraphNodeCoordinates: {
Expand Down
4 changes: 2 additions & 2 deletions src/schema/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const GraphNode = objectType({
name: 'GraphNode',
definition: (t) => {
t.implements(BaseGraphNode);
t.nonNull.field('device', { type: 'Device' });
t.nonNull.string('name');
t.field('device', { type: 'Device' });
},
});

Expand Down Expand Up @@ -168,7 +169,6 @@ export const TopologyQuery = extendType({
const { filter } = args;

const topologyDevices = await topologyDiscoveryGraphQLAPI?.getTopologyDevices();
// console.log(JSON.stringify(topologyDevices, null, 2));
const labels = filter?.labels ?? [];
const dbLabels = await prisma.label.findMany({ where: { name: { in: labels } } });
const labelIds = dbLabels.map((l) => l.id);
Expand Down

0 comments on commit 38e861c

Please sign in to comment.