mirror of
https://github.com/unraid/api.git
synced 2026-01-15 05:00:16 -06:00
change id(String->IDadd HOF to create basic subscriptions and fixed server listening to httpServer instead of stoppable wrapper
Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
@@ -80,12 +80,49 @@ module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pub
|
||||
|
||||
const { withFilter } = $injector.resolve('graphql-subscriptions');
|
||||
|
||||
const createBasicSubscription = (name, moduleToRun) => {
|
||||
return {
|
||||
subscribe: () => {
|
||||
publish(name, 'UPDATED', {
|
||||
moduleToRun,
|
||||
forever: true
|
||||
});
|
||||
return pubsub.asyncIterator(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
Query: {
|
||||
info: () => ({}),
|
||||
vms: () => ({})
|
||||
},
|
||||
Subscription: {
|
||||
apikeys: {
|
||||
subscribe: () => {
|
||||
// Not sure how we're going to secure this
|
||||
return pubsub.asyncIterator('apikeys');
|
||||
}
|
||||
},
|
||||
array: {
|
||||
...createBasicSubscription('array', 'get-array')
|
||||
},
|
||||
devices: {
|
||||
...createBasicSubscription('devices', 'get-devices')
|
||||
},
|
||||
dockerContainers: {
|
||||
...createBasicSubscription('docker/containers', 'docker/get-containers')
|
||||
},
|
||||
dockerNetworks: {
|
||||
...createBasicSubscription('docker/networks', 'docker/get-networks')
|
||||
},
|
||||
info: {
|
||||
...createBasicSubscription('info', 'get-info')
|
||||
},
|
||||
me: {
|
||||
subscribe: withFilter(() => pubsub.asyncIterator('user'), (payload, _, context) => payload.user.node.id === context.user.id),
|
||||
resolve: payload => payload.user
|
||||
},
|
||||
ping: {
|
||||
subscribe: () => {
|
||||
startPing();
|
||||
@@ -93,35 +130,22 @@ module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pub
|
||||
}
|
||||
},
|
||||
services: {
|
||||
subscribe: () => {
|
||||
publish('services', 'UPDATED', {
|
||||
moduleToRun: 'get-services',
|
||||
forever: true
|
||||
})
|
||||
return pubsub.asyncIterator('services');
|
||||
}
|
||||
...createBasicSubscription('services', 'get-services')
|
||||
},
|
||||
user: {
|
||||
subscribe: () => pubsub.asyncIterator('user')
|
||||
shares: {
|
||||
...createBasicSubscription('shares', 'get-shares')
|
||||
},
|
||||
unassignedDevices: {
|
||||
...createBasicSubscription('devices/unassigned', 'get-unassigned-devices')
|
||||
},
|
||||
users: {
|
||||
subscribe: () => pubsub.asyncIterator('users')
|
||||
...createBasicSubscription('users', 'get-users')
|
||||
},
|
||||
me: {
|
||||
subscribe: withFilter(() => pubsub.asyncIterator('user'), (payload, _, context) => payload.user.node.id === context.user.id),
|
||||
resolve: payload => payload.user
|
||||
vars: {
|
||||
...createBasicSubscription('vars', 'get-vars')
|
||||
},
|
||||
info: {
|
||||
subscribe: () => pubsub.asyncIterator('info')
|
||||
},
|
||||
array: {
|
||||
subscribe: () => {
|
||||
publish('array', 'UPDATED', {
|
||||
moduleToRun: 'get-array',
|
||||
forever: true
|
||||
})
|
||||
return pubsub.asyncIterator('array');
|
||||
}
|
||||
vms: {
|
||||
...createBasicSubscription('vms/domains', 'vms/get-domains')
|
||||
}
|
||||
},
|
||||
JSON: GraphQLJSON,
|
||||
|
||||
@@ -20,6 +20,15 @@ type Mutation {
|
||||
updateApikey(name: String!, input: updateApikeyInput): ApiKey @func(module: "apikeys/name/update-apikey")
|
||||
}
|
||||
|
||||
type ApikeysSubscription {
|
||||
mutation: MutationType!
|
||||
node: ApiKey
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
apikeys: ApikeysSubscription
|
||||
}
|
||||
|
||||
type ApiKey {
|
||||
name: String!
|
||||
key: String!
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
type App {
|
||||
id: ID!
|
||||
}
|
||||
@@ -26,7 +26,7 @@ type Subscription {
|
||||
|
||||
input arrayDiskInput {
|
||||
"""Disk ID"""
|
||||
id: String!
|
||||
id: ID!
|
||||
"""The slot for the disk"""
|
||||
slot: Int
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
type Query {
|
||||
device(id: String!): Device @func(module: "devices/device/get-device")
|
||||
device(id: ID!): Device @func(module: "devices/device/get-device")
|
||||
devices: [Device]! @func(module: "get-devices")
|
||||
}
|
||||
|
||||
type Device {
|
||||
id: String!
|
||||
id: ID!
|
||||
tag: String
|
||||
device: String
|
||||
sectors: String
|
||||
sectorSize: String
|
||||
}
|
||||
}
|
||||
|
||||
type DevicesSubscription {
|
||||
mutation: MutationType!
|
||||
node: [Device!]
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
devices: DevicesSubscription!
|
||||
device(id: ID!): DevicesSubscription!
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
type Query {
|
||||
"""Single disk"""
|
||||
disk(id: String!): Disk @func(module: "disks/id/get-disk")
|
||||
disk(id: ID!): Disk @func(module: "disks/id/get-disk")
|
||||
"""Mulitiple disks"""
|
||||
disks: [Disk]! @func(module: "get-disks")
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
mountDisk(id: String!): Disk
|
||||
unmountDisk(id: String!): Disk
|
||||
mountDisk(id: ID!): Disk
|
||||
unmountDisk(id: ID!): Disk
|
||||
|
||||
clearDiskStatistics(id: String!): JSON
|
||||
clearDiskStatistics(id: ID!): JSON
|
||||
}
|
||||
|
||||
type Disk {
|
||||
@@ -17,7 +17,7 @@ type Disk {
|
||||
idx: String!
|
||||
name: String!
|
||||
device: String!
|
||||
id: String!
|
||||
id: ID!
|
||||
size: Int!
|
||||
status: DiskStatus!
|
||||
rotational: Boolean!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
type Query {
|
||||
"""Docker network"""
|
||||
dockerNetwork(id: String!): DockerNetwork! @func(module: "docker/get-network")
|
||||
dockerNetwork(id: ID!): DockerNetwork! @func(module: "docker/get-network")
|
||||
"""All Docker networks"""
|
||||
dockerNetworks(all: Boolean): [DockerNetwork]! @func(module: "docker/get-networks")
|
||||
}
|
||||
@@ -21,7 +21,7 @@ type Subscription {
|
||||
|
||||
type DockerNetwork {
|
||||
name: String
|
||||
id: String
|
||||
id: ID
|
||||
created: String
|
||||
scope: String
|
||||
driver: String
|
||||
|
||||
@@ -10,7 +10,7 @@ type Devices {
|
||||
}
|
||||
|
||||
type Gpu {
|
||||
id: String!
|
||||
id: ID!
|
||||
type: String!
|
||||
typeid: String!
|
||||
vendorname: String!
|
||||
@@ -35,7 +35,7 @@ type Network {
|
||||
}
|
||||
|
||||
type Pci {
|
||||
id: String
|
||||
id: ID!
|
||||
type: String
|
||||
typeid: String
|
||||
vendorname: String
|
||||
@@ -47,6 +47,6 @@ type Pci {
|
||||
}
|
||||
|
||||
type Usb {
|
||||
id: String
|
||||
id: ID!
|
||||
name: String
|
||||
}
|
||||
@@ -8,7 +8,7 @@ type Query {
|
||||
|
||||
"""The current user"""
|
||||
type Me implements UserAccount {
|
||||
id: String!
|
||||
id: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
role: String!
|
||||
@@ -16,7 +16,7 @@ type Me implements UserAccount {
|
||||
}
|
||||
|
||||
type MeSubscription {
|
||||
mutation: UpdateOnlyMutationType
|
||||
mutation: UpdateOnlyMutationType!
|
||||
node: Me
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
interface UserAccount {
|
||||
id: String!
|
||||
id: ID!
|
||||
name: String!
|
||||
description: String!
|
||||
role: String!
|
||||
@@ -11,7 +11,7 @@ input usersInput {
|
||||
|
||||
type Query {
|
||||
"""User account"""
|
||||
user(id: String!): User @func(module: "users/id/get-user")
|
||||
user(id: ID!): User @func(module: "users/id/get-user")
|
||||
"""User accounts"""
|
||||
users(input: usersInput): [User!]! @func(module: "get-users", query: { slim: false })
|
||||
}
|
||||
@@ -43,13 +43,13 @@ type UsersSubscription {
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
user(id: String!): UserSubscription
|
||||
user(id: ID!): UserSubscription
|
||||
users: UsersSubscription
|
||||
}
|
||||
|
||||
"""A local user account"""
|
||||
type User implements UserAccount {
|
||||
id: String!
|
||||
id: ID!
|
||||
"""A unique name for the user"""
|
||||
name: String!
|
||||
description: String!
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
type Query {
|
||||
"""Virtual machine"""
|
||||
vm(name: String!): Domain @func(module: "vms/domains/domain/get-domain")
|
||||
vm(name: String!): VmDomain! @func(module: "vms/domains/domain/get-domain")
|
||||
"""Virtual machines"""
|
||||
vms: Vms
|
||||
}
|
||||
|
||||
type Vms {
|
||||
domains: [Domain] @func(module: "vms/get-domains")
|
||||
domains: [VmDomain!] @func(module: "vms/get-domains")
|
||||
}
|
||||
|
||||
type VmDomainSubscription {
|
||||
mutation: MutationType!
|
||||
node: [VmDomain!]
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
vms: VmDomainSubscription!
|
||||
}
|
||||
|
||||
enum VmState {
|
||||
@@ -17,7 +26,7 @@ enum VmState {
|
||||
}
|
||||
|
||||
"""A virtual machine"""
|
||||
type Domain {
|
||||
type VmDomain {
|
||||
uuid: ID!
|
||||
"""Operating system type"""
|
||||
osType: String
|
||||
|
||||
@@ -5,5 +5,15 @@ type Query {
|
||||
# vmNetworks: [VmNetwork]
|
||||
}
|
||||
|
||||
# type VmNetwork {
|
||||
# }
|
||||
type VmNetwork {
|
||||
__placeholderType: String
|
||||
}
|
||||
|
||||
type VmNetworksSubscription {
|
||||
mutation: MutationType!
|
||||
node: [VmNetwork!]
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
vmNetworks: VmNetworksSubscription!
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ module.exports = function ($injector, fs, net, express, config, log, getEndpoint
|
||||
|
||||
graphApp.installSubscriptionHandlers(httpServer);
|
||||
|
||||
server = stoppable(httpServer.listen(port, () => {
|
||||
server = stoppable(httpServer).listen(port, () => {
|
||||
// Downgrade process user to owner of this file
|
||||
return fs.stat(__filename, (error, stats) => {
|
||||
if (error) {
|
||||
@@ -103,7 +103,7 @@ module.exports = function ($injector, fs, net, express, config, log, getEndpoint
|
||||
|
||||
return process.setuid(stats.uid);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
// Port is a UNIX socket file
|
||||
if (isNaN(parseInt(port, 10))) {
|
||||
|
||||
Reference in New Issue
Block a user