const os = require('os') const typeDefs = ` type CPUTime { user: Int! nice: Int! sys: Int! idle: Int! irq: Int! } type CPU { model: String! speed: Int! times: CPUTime! } type NetworkAddress { address: String! netmask: String! family: String! mac: String! internal: Boolean! cidr: String! scopied: Int } type NetworkInterface { name: String! addresses: [ NetworkAddress ]! } type System { apiVersion: String! hostname: String! type: String! platform: String! arch: String! release: String! uptime: String! loadavg: [ Float! ]! totalmem: String! freemem: String! cpus: [ CPU! ]! networkInterfaces: [ NetworkInterface ]! } extend type Query { system: System! } ` function system () { return { apiVersion: '0.1', hostname: os.hostname(), type: os.type(), platform: os.platform(), arch: os.arch(), release: os.release(), uptime: os.uptime(), loadavg: os.loadavg(), totalmem: os.totalmem(), freemem: os.freemem(), cpus: os.cpus(), networkInterfaces: () => { const interfaces = os.networkInterfaces() const ifaceArray = [] for (let key in interfaces) { ifaceArray.push({ name: key, addresses: interfaces[key] }) } return ifaceArray } } } const resolvers = { Query: { system } } module.exports = { typeDefs, resolvers }