diff --git a/src/external-api/topology-discovery-graphql.ts b/src/external-api/topology-discovery-graphql.ts index cfd24f83..26ec42e3 100644 --- a/src/external-api/topology-discovery-graphql.ts +++ b/src/external-api/topology-discovery-graphql.ts @@ -33,6 +33,12 @@ type CoordinatesParam = { y: number; }; +type DeviceMetadataFilters = { + deviceName?: string | null; + topologyType?: 'PhysicalTopology' | 'PtpTopology' | 'EthTopology' | 'NetworkTopology' | 'MplsTopology' | null; + polygon?: number[][][] | null; +}; + const GET_SHORTEST_PATH = gql` query GetShortestPath($deviceFrom: ID!, $deviceTo: ID!, $collection: NetRoutingPathOutputCollections) { netRoutingPaths(deviceFrom: $deviceFrom, deviceTo: $deviceTo, outputCollection: $collection) { @@ -644,9 +650,9 @@ function getTopologyDiscoveryApi() { return response.syncePathToGm.nodes; } - async function getDeviceMetadata(): Promise { + async function getDeviceMetadata(filters?: DeviceMetadataFilters): Promise { const response = await client.request(DEVICE_METADATA, { - filters: undefined, + filters, }); return response; } diff --git a/src/schema/api.graphql b/src/schema/api.graphql index f828ad21..4091f9a9 100644 --- a/src/schema/api.graphql +++ b/src/schema/api.graphql @@ -366,6 +366,12 @@ input FilterDevicesInput { labels: [String!] } +input FilterDevicesMetadatasInput { + deviceName: String + polygon: PolygonInput + topologyType: TopologyType +} + input FilterLabelsInput { name: String! } @@ -639,6 +645,10 @@ type PhyTopologyVersionData { nodes: [GraphVersionNode!]! } +input PolygonInput { + polygon: [[[Float!]!]!] +} + type PtpDeviceDetails { clockAccuracy: String clockClass: Int @@ -705,7 +715,7 @@ type Query { calculatedDiff(deviceId: String!, transactionId: String!): CalculatedDiffPayload! countries(after: String, before: String, first: Int, last: Int): CountryConnection! dataStore(deviceId: String!, transactionId: String!): DataStore - deviceMetadata: DeviceMetadata + deviceMetadata(filter: FilterDevicesMetadatasInput): DeviceMetadata devices( after: String before: String @@ -877,6 +887,14 @@ enum TopologyLayer { PtpTopology } +enum TopologyType { + EthTopology + MplsTopology + NetworkTopology + PhysicalTopology + PtpTopology +} + type Transaction { changes: [TransactionChange!]! lastCommitTime: String! diff --git a/src/schema/nexus-typegen.ts b/src/schema/nexus-typegen.ts index b6af3978..c65deaa4 100644 --- a/src/schema/nexus-typegen.ts +++ b/src/schema/nexus-typegen.ts @@ -133,6 +133,12 @@ export interface NexusGenInputs { deviceName?: string | null; // String labels?: string[] | null; // [String!] }; + FilterDevicesMetadatasInput: { + // input type + deviceName?: string | null; // String + polygon?: NexusGenInputs['PolygonInput'] | null; // PolygonInput + topologyType?: NexusGenEnums['TopologyType'] | null; // TopologyType + }; FilterLabelsInput: { // input type name: string; // String! @@ -157,6 +163,10 @@ export interface NexusGenInputs { x: number; // Float! y: number; // Float! }; + PolygonInput: { + // input type + polygon?: number[][][] | null; // [[[Float!]!]!] + }; StreamOrderByInput: { // input type direction: NexusGenEnums['SortDirection']; // SortDirection! @@ -218,6 +228,7 @@ export interface NexusGenEnums { SortDirection: 'ASC' | 'DESC'; SortStreamBy: 'createdAt' | 'deviceName' | 'streamName'; TopologyLayer: 'EthTopology' | 'MplsTopology' | 'PhysicalTopology' | 'PtpTopology'; + TopologyType: 'EthTopology' | 'MplsTopology' | 'NetworkTopology' | 'PhysicalTopology' | 'PtpTopology'; } export interface NexusGenScalars { @@ -2527,6 +2538,10 @@ export interface NexusGenArgTypes { deviceId: string; // String! transactionId: string; // String! }; + deviceMetadata: { + // args + filter?: NexusGenInputs['FilterDevicesMetadatasInput'] | null; // FilterDevicesMetadatasInput + }; devices: { // args after?: string | null; // String diff --git a/src/schema/topology.ts b/src/schema/topology.ts index ad49a785..8fd13b21 100644 --- a/src/schema/topology.ts +++ b/src/schema/topology.ts @@ -8,6 +8,7 @@ import { enumType, interfaceType, queryField, + arg, } from 'nexus'; import config from '../config'; import { fromGraphId } from '../helpers/id-helper'; @@ -853,13 +854,42 @@ export const DeviceMetadata = objectType({ }, }); +export const TopologyType = enumType({ + name: 'TopologyType', + members: ['PhysicalTopology', 'PtpTopology', 'EthTopology', 'NetworkTopology', 'MplsTopology'], +}); + +export const PolygonInputType = inputObjectType({ + name: 'PolygonInput', + definition(t) { + t.list.nonNull.list.nonNull.list.nonNull.float('polygon'); + }, +}); + +export const FilterDevicesMetadatasInput = inputObjectType({ + name: 'FilterDevicesMetadatasInput', + definition: (t) => { + t.string('deviceName'); + t.field('topologyType', { type: TopologyType }); + t.field('polygon', { type: PolygonInputType }); + }, +}); + export const deviceMetadataQuery = queryField('deviceMetadata', { type: DeviceMetadata, + args: { + filter: FilterDevicesMetadatasInput, + }, resolve: async (_, args, { prisma, topologyDiscoveryGraphQLAPI }) => { if (!topologyDiscoveryGraphQLAPI) { return null; } - const deviceMetadataResult = await topologyDiscoveryGraphQLAPI.getDeviceMetadata(); + + const deviceMetadataResult = await topologyDiscoveryGraphQLAPI.getDeviceMetadata({ + deviceName: args.filter?.deviceName, + topologyType: args.filter?.topologyType, + polygon: args.filter?.polygon?.polygon, + }); const dbDevices = await prisma.device.findMany({ include: {