1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 ]!
- }
- extend type Query {
- 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 Mutation {
- hello: String!
- }
- `
- const resolvers = {
- Query: {
- 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
- }
- }
- }
- module.exports = { typeDefs, resolvers }
|