diff --git a/app/graphql/schema/resolvers.ts b/app/graphql/schema/resolvers.ts index c283e1e13..fc6c42faa 100644 --- a/app/graphql/schema/resolvers.ts +++ b/app/graphql/schema/resolvers.ts @@ -10,7 +10,7 @@ import GraphQLJSON from 'graphql-type-json'; import GraphQLLong from 'graphql-type-long'; import GraphQLUUID from 'graphql-type-uuid'; import { run, publish } from '../../run'; -import { userCache } from '../../cache'; +import { userCache, CachedUser } from '../../cache'; import { hasSubscribedToChannel, canPublishToChannel } from '../../ws'; const { ensurePermission } = utils; @@ -93,66 +93,14 @@ export const resolvers = { info: () => ({}), vms: () => ({}), server(name: string) { + const mine = userCache.get('mine'); + // Single server - // return cache.get(); + return mine?.servers.find(server => server.name === name); }, - servers() { - const mockData = [{ - online: true, - info: { - machineId: '38ed954556087cd0921d3ce69adaa57f', - apps: { - installed: 100, - started: 1 - }, - versions: { - unraid: '6.9.0-beta12' - }, - os: { - hostname: 'tower' - } - }, - array: { - state: 'started', - capacity: { - bytes: { - free: 1222900940800, - total: 1347826987008, - used: 124926046208 - } - } - }, - services: [ - { - name: 'emhttpd', - online: true, - version: null - }, - { - name: 'rest-api', - online: false, - version: null - }, - { - name: 'graphql-api', - online: true, - version: '2.4.9' - }, - { - name: 'plugins', - online: null, - version: '1.1.5' - } - ], - my_servers: { - url: 'case-model.png', - serverCase: 'custom' - } - }]; - + servers() { // All servers - return userCache.get('mine'); - // return cache.data; + return userCache.get('mine')?.servers; } }, Subscription: { diff --git a/app/graphql/schema/types/servers/server.graphql b/app/graphql/schema/types/servers/server.graphql index 3a4a647ae..15d395c52 100644 --- a/app/graphql/schema/types/servers/server.graphql +++ b/app/graphql/schema/types/servers/server.graphql @@ -1,15 +1,15 @@ type Query { - server(name: String!): Server + server(name: String!): JSON servers: [JSON] } type ServerSubscription { mutation: UpdateOnlyMutationType! - node: Server! + node: JSON! } type ServersSubscription { mutation: UpdateOnlyMutationType! - node: [Server!] + node: [JSON!] } type Subscription { @@ -17,12 +17,16 @@ type Subscription { servers: ServersSubscription } -# type Status = 'Online' | 'Offline'; +type Status = 'online' | 'offline'; +type IpAddress = String; -# type Server { -# name: String! -# status: String! -# wanIp: String! -# localUrl: String! -# remoteUrl: String! -# } \ No newline at end of file +type Server { + guid: string; + apikey: string; + name: string; + status: Status; + wanip: IpAddress; + lanip: IpAddress; + localurl: string; + remoteurl: string; +} \ No newline at end of file diff --git a/app/server.ts b/app/server.ts index aadc96203..2763fa92e 100644 --- a/app/server.ts +++ b/app/server.ts @@ -276,6 +276,7 @@ const connectToMothership = async (currentRetryAttempt: number = 0) => { // Proxy this to the http endpoint if (message.type === 'query' || message.type === 'mutation') { + log.debug(`Got a ${message.type} request from mothership, forwarding to socket.`); request.post('http://unix:/var/run/graphql-api.sock:/graphql', { body: JSON.stringify({ operationName: null, @@ -296,7 +297,7 @@ const connectToMothership = async (currentRetryAttempt: number = 0) => { try { const data = JSON.parse(response.body).data; const payload = { data }; - log.debug('Sending payload to mothership', payload); + log.debug('Replying to mothership with payload', payload); mothership.send(JSON.stringify({ type: 'data', payload @@ -308,9 +309,9 @@ const connectToMothership = async (currentRetryAttempt: number = 0) => { }); } - const isUserObject = (x): x is CachedUser => { + const isUserObject = (data): data is CachedUser => { const keys = Object.keys(data); - return keys.includes('profile') && keys.includes('servers') && keys.length === 2 + return keys.includes('profile') && keys.includes('servers') && keys.length === 2; }; if (message.type === 'proxy-data') { diff --git a/package-lock.json b/package-lock.json index 02d47af81..3aec4e1ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1046,12 +1046,9 @@ } }, "graphql": { - "version": "14.6.0", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-14.6.0.tgz", - "integrity": "sha512-VKzfvHEKybTKjQVpTFrA5yUq2S9ihcZvfJAtsDBBCuV6wauPu1xl/f9ehgVf0FcEJJs4vz6ysb/ZMkGigQZseg==", - "requires": { - "iterall": "^1.2.2" - } + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.1.0.tgz", + "integrity": "sha512-0TVyfOlCGhv/DBczQkJmwXOK6fjWkjzY3Pt7wY8i0gcYXq8aogG3weCsg48m72lywKSeOqedEHvVPOvZvSD51Q==" }, "systeminformation": { "version": "4.26.9",