or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

colors.mddata-formats.mddate-time.mdfinancial.mdgeographic.mdidentifiers.mdindex.mdnetwork.mdnumeric.mdspecialized.mdstring-text.mdutilities.md
tile.json

network.mddocs/

Network and Address Scalars

Network-related validation including IP addresses, MAC addresses, and port numbers. These scalars provide validation for networking data commonly used in system administration and network-aware applications.

Capabilities

IP Scalar

Validates IP addresses (both IPv4 and IPv6).

/**
 * GraphQL scalar for IP address validation
 * Accepts both IPv4 and IPv6 format addresses
 */
const GraphQLIP: GraphQLScalarType;

Example Values:

  • "192.168.1.1" (IPv4)
  • "10.0.0.1" (IPv4)
  • "2001:0db8:85a3:0000:0000:8a2e:0370:7334" (IPv6)
  • "::1" (IPv6 loopback)
  • "fe80::1" (IPv6 link-local)

IPv4 Scalar

Validates IPv4 addresses specifically.

/**
 * GraphQL scalar for IPv4 address validation
 * Accepts IPv4 format: xxx.xxx.xxx.xxx (0-255 for each octet)
 */
const GraphQLIPv4: GraphQLScalarType;

Example Values:

  • "192.168.1.1"
  • "10.0.0.1"
  • "127.0.0.1"
  • "255.255.255.255"
  • "0.0.0.0"

IPv6 Scalar

Validates IPv6 addresses specifically.

/**
 * GraphQL scalar for IPv6 address validation
 * Accepts IPv6 format including compressed notation
 */
const GraphQLIPv6: GraphQLScalarType;

Example Values:

  • "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
  • "2001:db8:85a3::8a2e:370:7334" (compressed)
  • "::1" (loopback)
  • "fe80::1" (link-local)
  • "::ffff:192.0.2.1" (IPv4-mapped)

MAC Scalar

Validates MAC (Media Access Control) address format.

/**
 * GraphQL scalar for MAC address validation
 * Accepts MAC address in various common formats
 */
const GraphQLMAC: GraphQLScalarType;

Example Values:

  • "00:14:22:01:23:45"
  • "00-14-22-01-23-45"
  • "0014.2201.2345"
  • "001422012345"

Port Scalar

Validates network port numbers (1-65535).

/**
 * GraphQL scalar for port number validation
 * Accepts integers from 1 to 65535 (valid port range)
 */
const GraphQLPort: GraphQLScalarType;

Example Values:

  • 80 (HTTP)
  • 443 (HTTPS)
  • 22 (SSH)
  • 3000 (development server)
  • 65535 (maximum port)

Usage Examples

import { 
  GraphQLIP,
  GraphQLIPv4,
  GraphQLIPv6,
  GraphQLMAC,
  GraphQLPort
} from "graphql-scalars";

// In a GraphQL schema
const ServerType = new GraphQLObjectType({
  name: "Server",
  fields: {
    ipAddress: { type: GraphQLIP },
    ipv4Address: { type: GraphQLIPv4 },
    ipv6Address: { type: GraphQLIPv6 },
    macAddress: { type: GraphQLMAC },
    port: { type: GraphQLPort },
  },
});

// Using with type definitions
const typeDefs = `
  scalar IP
  scalar IPv4
  scalar IPv6
  scalar MAC
  scalar Port
  
  type Server {
    hostname: String!
    ipAddress: IP
    ipv4Address: IPv4
    ipv6Address: IPv6
    macAddress: MAC
    port: Port
  }
  
  type NetworkInterface {
    name: String!
    ipv4: IPv4
    ipv6: IPv6
    mac: MAC
  }
`;

GraphQL Operations:

query GetServerInfo($serverId: ID!) {
  server(id: $serverId) {
    hostname
    ipAddress
    port
    networkInterfaces {
      name
      ipv4
      ipv6
      mac
    }
  }
}

mutation UpdateServer($id: ID!, $input: ServerInput!) {
  updateServer(id: $id, input: $input) {
    id
    ipAddress
    port
  }
}

Variables:

{
  "serverId": "srv-123",
  "input": {
    "ipAddress": "192.168.1.100",
    "port": 8080,
    "macAddress": "00:14:22:01:23:45"
  }
}

Validation Behavior

Each network scalar performs specific format validation:

  • IP: Accepts both IPv4 and IPv6, validates format for both
  • IPv4: Validates 4 octets (0-255) separated by dots
  • IPv6: Validates 8 groups of 4 hexadecimal digits, supports compression
  • MAC: Accepts multiple formats (colon, dash, dot, no separator)
  • Port: Ensures integer is within valid port range (1-65535)

Validation Examples:

// Valid network data
const validServer = {
  ipAddress: "192.168.1.1",        // Valid IPv4
  ipv6Address: "::1",              // Valid IPv6 (compressed)
  macAddress: "00:14:22:01:23:45", // Valid MAC format
  port: 3000                       // Valid port number
};

// Invalid network data
const invalidServer = {
  ipAddress: "999.999.999.999",    // Invalid IPv4 (octets > 255)
  ipv6Address: "invalid::address", // Invalid IPv6 format
  macAddress: "xx:xx:xx:xx:xx:xx", // Invalid MAC (non-hex)
  port: 70000                      // Invalid port (> 65535)
};

Common Use Cases

IP Addresses are used for:

  • Server configuration
  • Network monitoring
  • Access control lists
  • Load balancer configuration

MAC Addresses are used for:

  • Network device identification
  • Wake-on-LAN functionality
  • Network security policies
  • Asset management

Port Numbers are used for:

  • Service configuration
  • Firewall rules
  • Load balancing
  • Container port mapping

Type Definitions

// String constants for schema building
const IP: string;    // "scalar IP"
const IPv4: string;  // "scalar IPv4"
const IPv6: string;  // "scalar IPv6"
const MAC: string;   // "scalar MAC"
const Port: string;  // "scalar Port"

Mock Data

// Mock data generators for testing
const IPMock: () => string;
const IPv4Mock: () => string;
const IPv6Mock: () => string;
const MACMock: () => string;
const PortMock: () => number;

Error Handling

Network scalars provide specific validation error messages:

// IP validation errors
"Value is not a valid IP address: 999.999.999.999"

// MAC validation errors
"Value is not a valid MAC address: xx:xx:xx:xx:xx:xx"

// Port validation errors
"Value is not a valid port number: 70000 (must be 1-65535)"