From 64de925f4fad82ebff7efedddf6aec8d19c59bdb Mon Sep 17 00:00:00 2001 From: Peto Date: Wed, 21 Feb 2024 13:32:01 +0100 Subject: [PATCH 1/4] lint fix --- src/helpers/topology.helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/helpers/topology.helpers.ts b/src/helpers/topology.helpers.ts index 66bd1cb1..ce40b904 100644 --- a/src/helpers/topology.helpers.ts +++ b/src/helpers/topology.helpers.ts @@ -16,7 +16,6 @@ import { } from '../external-api/topology-network-types'; import { omitNullValue, unwrap } from './utils.helpers'; import { toGraphId } from './id-helper'; -import { log } from 'console'; type FilterInput = { labelIds?: string[] | null; From defece2e40aee8b66781624c36570639cac5d0e2 Mon Sep 17 00:00:00 2001 From: Peto Date: Tue, 27 Feb 2024 21:05:43 +0100 Subject: [PATCH 2/4] refactored query structure --- src/helpers/topology.helpers.ts | 49 ++++++------ src/schema/api.graphql | 43 ++++------- src/schema/nexus-typegen.ts | 129 ++++++++++++-------------------- src/schema/topology.ts | 37 +++------ 4 files changed, 97 insertions(+), 161 deletions(-) diff --git a/src/helpers/topology.helpers.ts b/src/helpers/topology.helpers.ts index ce40b904..619b3175 100644 --- a/src/helpers/topology.helpers.ts +++ b/src/helpers/topology.helpers.ts @@ -525,7 +525,7 @@ export function makeSynceTopologyNodes(synceDevices?: SynceTopologyQuery) { synceDeviceDetails: makeSynceDeviceDetails(node), status: getStatus(node.status), labels: node.labels?.map((l) => l) ?? [], - interfaces: + SynceGraphNodeInterfaces: node.synceInterfaces.edges ?.map((i) => { const interfaceNode = i?.node; @@ -534,32 +534,29 @@ export function makeSynceTopologyNodes(synceDevices?: SynceTopologyQuery) { } return { id: interfaceNode.id, - status: interfaceNode.status, name: interfaceNode.name, - synceDevice: { - id: interfaceNode.id, - name: interfaceNode.name, - status: interfaceNode.status, - synceDeviceInterfaces: - interfaceNode.synceDevice?.synceInterfaces.edges - ?.map((synceInterface) => { - if (!synceInterface?.node) { - return null; - } - return { - id: synceInterface.node.id, - name: synceInterface.node.name, - interface: { - synceEnabled: synceInterface?.node?.details?.synce_enabled, - rxQualityLevel: synceInterface?.node?.details?.rx_quality_level, - qualifiedForUse: synceInterface?.node?.details?.qualified_for_use, - notSelectedDueTo: synceInterface?.node?.details?.not_selected_due_to, - notQualifiedDueTo: synceInterface.node.details?.not_qualified_due_to, - }, - }; - }) - .filter(omitNullValue) ?? [], - }, + status: getStatus(interfaceNode.status), + interface: + interfaceNode.synceDevice?.synceInterfaces.edges?.map((n) => { + const node = n?.node; + if (!node) { + return null; + } + if (n.node && n.node.details) { + return { + id: n.node.id, + name: n.node.name, + details: { + synceEnabled: n.node.details.synce_enabled, + rxQualityLevel: n.node.details.rx_quality_level, + qualifiedForUse: n.node.details.qualified_for_use, + notQualifiedDueTo: n.node.details.not_qualified_due_to, + notSelectedDueTo: n.node.details.not_selected_due_to, + }, + }; + } + return null; + }) || [], }; }) .filter(omitNullValue) ?? [], diff --git a/src/schema/api.graphql b/src/schema/api.graphql index 7e27bdc5..82622405 100644 --- a/src/schema/api.graphql +++ b/src/schema/api.graphql @@ -340,8 +340,8 @@ type GraphNodeInterfaceDetails { } type GraphSynceNodeInterface { - details: synceDeviceInterfaces id: String! + interface: [SynceNodeInterface]! name: String! status: GraphEdgeStatus! } @@ -365,21 +365,6 @@ type InstallDevicePayload { device: Device! } -type Interface { - notQualifiedDueTo: String - notSelectedDueTo: String - qualifiedForUse: String - rxQualityLevel: String - synceEnabled: Boolean -} - -type Interfaces { - id: String! - name: String! - status: GraphEdgeStatus! - synceDevice: SynceDevice! -} - type IsOkResponse { isOk: Boolean! } @@ -603,18 +588,14 @@ type SyncFromNetworkPayload { dataStore: DataStore } -type SynceDevice { - synceDeviceInterfaces: [synceDeviceInterfaces]! -} - type SynceDeviceDetails { selectedForUse: String } type SynceGraphNode { + SynceGraphNodeInterfaces: [GraphSynceNodeInterface!]! coordinates: GraphNodeCoordinates! id: ID! - interfaces: [Interfaces!]! labels: [String!] name: String! nodeId: String! @@ -622,6 +603,20 @@ type SynceGraphNode { synceDeviceDetails: SynceDeviceDetails! } +type SynceGraphNodeInterfaceDetails { + notQualifiedDueTo: String + notSelectedDueTo: String + qualifiedForUse: String + rxQualityLevel: String + synceEnabled: Boolean +} + +type SynceNodeInterface { + details: SynceGraphNodeInterfaceDetails! + id: String! + name: String! +} + type SynceTopology { edges: [GraphEdge!]! nodes: [SynceGraphNode!]! @@ -741,9 +736,3 @@ type ZonesConnection { pageInfo: PageInfo! totalCount: Int! } - -type synceDeviceInterfaces { - id: String! - interface: Interface! - name: String! -} diff --git a/src/schema/nexus-typegen.ts b/src/schema/nexus-typegen.ts index e2c51bb0..7937a54c 100644 --- a/src/schema/nexus-typegen.ts +++ b/src/schema/nexus-typegen.ts @@ -357,8 +357,8 @@ export interface NexusGenObjects { }; GraphSynceNodeInterface: { // root type - details?: NexusGenRootTypes['synceDeviceInterfaces'] | null; // synceDeviceInterfaces id: string; // String! + interface: Array; // [SynceNodeInterface]! name: string; // String! status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! }; @@ -381,21 +381,6 @@ export interface NexusGenObjects { // root type device: NexusGenRootTypes['Device']; // Device! }; - Interface: { - // root type - notQualifiedDueTo?: string | null; // String - notSelectedDueTo?: string | null; // String - qualifiedForUse?: string | null; // String - rxQualityLevel?: string | null; // String - synceEnabled?: boolean | null; // Boolean - }; - Interfaces: { - // root type - id: string; // String! - name: string; // String! - status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! - synceDevice: NexusGenRootTypes['SynceDevice']; // SynceDevice! - }; IsOkResponse: { // root type isOk: boolean; // Boolean! @@ -529,25 +514,35 @@ export interface NexusGenObjects { // root type dataStore?: NexusGenRootTypes['DataStore'] | null; // DataStore }; - SynceDevice: { - // root type - synceDeviceInterfaces: Array; // [synceDeviceInterfaces]! - }; SynceDeviceDetails: { // root type selectedForUse?: string | null; // String }; SynceGraphNode: { // root type + SynceGraphNodeInterfaces: NexusGenRootTypes['GraphSynceNodeInterface'][]; // [GraphSynceNodeInterface!]! coordinates: NexusGenRootTypes['GraphNodeCoordinates']; // GraphNodeCoordinates! id: string; // ID! - interfaces: NexusGenRootTypes['Interfaces'][]; // [Interfaces!]! labels?: string[] | null; // [String!] name: string; // String! nodeId: string; // String! status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! synceDeviceDetails: NexusGenRootTypes['SynceDeviceDetails']; // SynceDeviceDetails! }; + SynceGraphNodeInterfaceDetails: { + // root type + notQualifiedDueTo?: string | null; // String + notSelectedDueTo?: string | null; // String + qualifiedForUse?: string | null; // String + rxQualityLevel?: string | null; // String + synceEnabled?: boolean | null; // Boolean + }; + SynceNodeInterface: { + // root type + details: NexusGenRootTypes['SynceGraphNodeInterfaceDetails']; // SynceGraphNodeInterfaceDetails! + id: string; // String! + name: string; // String! + }; SynceTopology: { // root type edges: NexusGenRootTypes['GraphEdge'][]; // [GraphEdge!]! @@ -620,12 +615,6 @@ export interface NexusGenObjects { pageInfo: NexusGenRootTypes['PageInfo']; // PageInfo! totalCount: number; // Int! }; - synceDeviceInterfaces: { - // root type - id: string; // String! - interface: NexusGenRootTypes['Interface']; // Interface! - name: string; // String! - }; } export interface NexusGenInterfaces { @@ -857,8 +846,8 @@ export interface NexusGenFieldTypes { }; GraphSynceNodeInterface: { // field return type - details: NexusGenRootTypes['synceDeviceInterfaces'] | null; // synceDeviceInterfaces id: string; // String! + interface: Array; // [SynceNodeInterface]! name: string; // String! status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! }; @@ -881,21 +870,6 @@ export interface NexusGenFieldTypes { // field return type device: NexusGenRootTypes['Device']; // Device! }; - Interface: { - // field return type - notQualifiedDueTo: string | null; // String - notSelectedDueTo: string | null; // String - qualifiedForUse: string | null; // String - rxQualityLevel: string | null; // String - synceEnabled: boolean | null; // Boolean - }; - Interfaces: { - // field return type - id: string; // String! - name: string; // String! - status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! - synceDevice: NexusGenRootTypes['SynceDevice']; // SynceDevice! - }; IsOkResponse: { // field return type isOk: boolean; // Boolean! @@ -1097,25 +1071,35 @@ export interface NexusGenFieldTypes { // field return type dataStore: NexusGenRootTypes['DataStore'] | null; // DataStore }; - SynceDevice: { - // field return type - synceDeviceInterfaces: Array; // [synceDeviceInterfaces]! - }; SynceDeviceDetails: { // field return type selectedForUse: string | null; // String }; SynceGraphNode: { // field return type + SynceGraphNodeInterfaces: NexusGenRootTypes['GraphSynceNodeInterface'][]; // [GraphSynceNodeInterface!]! coordinates: NexusGenRootTypes['GraphNodeCoordinates']; // GraphNodeCoordinates! id: string; // ID! - interfaces: NexusGenRootTypes['Interfaces'][]; // [Interfaces!]! labels: string[] | null; // [String!] name: string; // String! nodeId: string; // String! status: NexusGenEnums['GraphEdgeStatus']; // GraphEdgeStatus! synceDeviceDetails: NexusGenRootTypes['SynceDeviceDetails']; // SynceDeviceDetails! }; + SynceGraphNodeInterfaceDetails: { + // field return type + notQualifiedDueTo: string | null; // String + notSelectedDueTo: string | null; // String + qualifiedForUse: string | null; // String + rxQualityLevel: string | null; // String + synceEnabled: boolean | null; // Boolean + }; + SynceNodeInterface: { + // field return type + details: NexusGenRootTypes['SynceGraphNodeInterfaceDetails']; // SynceGraphNodeInterfaceDetails! + id: string; // String! + name: string; // String! + }; SynceTopology: { // field return type edges: NexusGenRootTypes['GraphEdge'][]; // [GraphEdge!]! @@ -1194,12 +1178,6 @@ export interface NexusGenFieldTypes { pageInfo: NexusGenRootTypes['PageInfo']; // PageInfo! totalCount: number; // Int! }; - synceDeviceInterfaces: { - // field return type - id: string; // String! - interface: NexusGenRootTypes['Interface']; // Interface! - name: string; // String! - }; BaseGraphNode: { // field return type coordinates: NexusGenRootTypes['GraphNodeCoordinates']; // GraphNodeCoordinates! @@ -1426,8 +1404,8 @@ export interface NexusGenFieldTypeNames { }; GraphSynceNodeInterface: { // field return type name - details: 'synceDeviceInterfaces'; id: 'String'; + interface: 'SynceNodeInterface'; name: 'String'; status: 'GraphEdgeStatus'; }; @@ -1450,21 +1428,6 @@ export interface NexusGenFieldTypeNames { // field return type name device: 'Device'; }; - Interface: { - // field return type name - notQualifiedDueTo: 'String'; - notSelectedDueTo: 'String'; - qualifiedForUse: 'String'; - rxQualityLevel: 'String'; - synceEnabled: 'Boolean'; - }; - Interfaces: { - // field return type name - id: 'String'; - name: 'String'; - status: 'GraphEdgeStatus'; - synceDevice: 'SynceDevice'; - }; IsOkResponse: { // field return type name isOk: 'Boolean'; @@ -1666,25 +1629,35 @@ export interface NexusGenFieldTypeNames { // field return type name dataStore: 'DataStore'; }; - SynceDevice: { - // field return type name - synceDeviceInterfaces: 'synceDeviceInterfaces'; - }; SynceDeviceDetails: { // field return type name selectedForUse: 'String'; }; SynceGraphNode: { // field return type name + SynceGraphNodeInterfaces: 'GraphSynceNodeInterface'; coordinates: 'GraphNodeCoordinates'; id: 'ID'; - interfaces: 'Interfaces'; labels: 'String'; name: 'String'; nodeId: 'String'; status: 'GraphEdgeStatus'; synceDeviceDetails: 'SynceDeviceDetails'; }; + SynceGraphNodeInterfaceDetails: { + // field return type name + notQualifiedDueTo: 'String'; + notSelectedDueTo: 'String'; + qualifiedForUse: 'String'; + rxQualityLevel: 'String'; + synceEnabled: 'Boolean'; + }; + SynceNodeInterface: { + // field return type name + details: 'SynceGraphNodeInterfaceDetails'; + id: 'String'; + name: 'String'; + }; SynceTopology: { // field return type name edges: 'GraphEdge'; @@ -1763,12 +1736,6 @@ export interface NexusGenFieldTypeNames { pageInfo: 'PageInfo'; totalCount: 'Int'; }; - synceDeviceInterfaces: { - // field return type name - id: 'String'; - interface: 'Interface'; - name: 'String'; - }; BaseGraphNode: { // field return type name coordinates: 'GraphNodeCoordinates'; diff --git a/src/schema/topology.ts b/src/schema/topology.ts index bf068d7f..cd071e70 100644 --- a/src/schema/topology.ts +++ b/src/schema/topology.ts @@ -66,8 +66,8 @@ export const GraphNodeInterface = objectType({ }, }); -export const Interface = objectType({ - name: 'Interface', +export const SynceGraphNodeInterfaceDetails = objectType({ + name: 'SynceGraphNodeInterfaceDetails', definition: (t) => { t.boolean('synceEnabled'); t.string('rxQualityLevel'); @@ -77,22 +77,22 @@ export const Interface = objectType({ }, }); -export const SynceDeviceInterfaces = objectType({ - name: 'synceDeviceInterfaces', +export const GraphSynceNodeInterface = objectType({ + name: 'GraphSynceNodeInterface', definition: (t) => { t.nonNull.string('id'); + t.nonNull.field('status', { type: GraphInterfaceStatus }); t.nonNull.string('name'); - t.nonNull.field('interface', { type: Interface }); + t.nonNull.list.field('interface', { type: SynceNodeInterface }); }, }); -export const GraphSynceNodeInterface = objectType({ - name: 'GraphSynceNodeInterface', +export const SynceNodeInterface = objectType({ + name: 'SynceNodeInterface', definition: (t) => { t.nonNull.string('id'); - t.nonNull.field('status', { type: GraphInterfaceStatus }); t.nonNull.string('name'); - t.field('details', { type: SynceDeviceInterfaces }); + t.nonNull.field('details', { type: SynceGraphNodeInterfaceDetails }); }, }); @@ -607,23 +607,6 @@ export const SynceDeviceDetails = objectType({ }, }); -export const SynceDevice = objectType({ - name: 'SynceDevice', - definition: (t) => { - t.nonNull.list.field('synceDeviceInterfaces', { type: SynceDeviceInterfaces }); - }, -}); - -export const Interfaces = objectType({ - name: 'Interfaces', - definition: (t) => { - t.nonNull.string('id'); - t.nonNull.string('name'); - t.nonNull.field('status', { type: GraphInterfaceStatus }); - t.nonNull.field('synceDevice', { type: SynceDevice }); - }, -}); - export const SynceGraphNode = objectType({ name: 'SynceGraphNode', definition: (t) => { @@ -633,7 +616,7 @@ export const SynceGraphNode = objectType({ t.nonNull.field('synceDeviceDetails', { type: SynceDeviceDetails }); t.nonNull.field('status', { type: GraphInterfaceStatus }); t.list.nonNull.string('labels'); - t.nonNull.list.field('interfaces', { type: nonNull(Interfaces) }); + t.nonNull.list.nonNull.field('SynceGraphNodeInterfaces', { type: nonNull(GraphSynceNodeInterface) }); t.nonNull.field('coordinates', { type: GraphNodeCoordinates }); }, }); From b5940b6f6224bd1beac135acca215e7dc285249b Mon Sep 17 00:00:00 2001 From: Peto Date: Tue, 27 Feb 2024 21:11:06 +0100 Subject: [PATCH 3/4] lint fix --- src/helpers/topology.helpers.ts | 3 +-- src/schema/topology.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/helpers/topology.helpers.ts b/src/helpers/topology.helpers.ts index 619b3175..a2d77125 100644 --- a/src/helpers/topology.helpers.ts +++ b/src/helpers/topology.helpers.ts @@ -538,8 +538,7 @@ export function makeSynceTopologyNodes(synceDevices?: SynceTopologyQuery) { status: getStatus(interfaceNode.status), interface: interfaceNode.synceDevice?.synceInterfaces.edges?.map((n) => { - const node = n?.node; - if (!node) { + if (!n?.node) { return null; } if (n.node && n.node.details) { diff --git a/src/schema/topology.ts b/src/schema/topology.ts index cd071e70..50c3fb74 100644 --- a/src/schema/topology.ts +++ b/src/schema/topology.ts @@ -77,25 +77,27 @@ export const SynceGraphNodeInterfaceDetails = objectType({ }, }); -export const GraphSynceNodeInterface = objectType({ - name: 'GraphSynceNodeInterface', +export const SynceNodeInterface = objectType({ + name: 'SynceNodeInterface', definition: (t) => { t.nonNull.string('id'); - t.nonNull.field('status', { type: GraphInterfaceStatus }); t.nonNull.string('name'); - t.nonNull.list.field('interface', { type: SynceNodeInterface }); + t.nonNull.field('details', { type: SynceGraphNodeInterfaceDetails }); }, }); -export const SynceNodeInterface = objectType({ - name: 'SynceNodeInterface', +export const GraphSynceNodeInterface = objectType({ + name: 'GraphSynceNodeInterface', definition: (t) => { t.nonNull.string('id'); + t.nonNull.field('status', { type: GraphInterfaceStatus }); t.nonNull.string('name'); - t.nonNull.field('details', { type: SynceGraphNodeInterfaceDetails }); + t.nonNull.list.field('interface', { type: SynceNodeInterface }); }, }); + + export const GraphNodeCoordinates = objectType({ name: 'GraphNodeCoordinates', definition: (t) => { From 0742a04dd8cf2456e9c8c467b68025d9cd2b1bd9 Mon Sep 17 00:00:00 2001 From: Peto Date: Tue, 27 Feb 2024 21:13:02 +0100 Subject: [PATCH 4/4] formatting --- src/schema/topology.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/schema/topology.ts b/src/schema/topology.ts index 50c3fb74..c3d30ead 100644 --- a/src/schema/topology.ts +++ b/src/schema/topology.ts @@ -96,8 +96,6 @@ export const GraphSynceNodeInterface = objectType({ }, }); - - export const GraphNodeCoordinates = objectType({ name: 'GraphNodeCoordinates', definition: (t) => {