diff --git a/packages/cloudapi-gql/src/api/key-value.js b/packages/cloudapi-gql/src/api/key-value.js index 738b3240..e53bb2d1 100644 --- a/packages/cloudapi-gql/src/api/key-value.js +++ b/packages/cloudapi-gql/src/api/key-value.js @@ -2,7 +2,8 @@ const forceArray = require('force-array'); const hasha = require('hasha'); module.exports.toKeyValue = r => - r && Object.keys(r).map(name => ({ + r && + Object.keys(r).map(name => ({ id: hasha(JSON.stringify({ name, value: r[name] })), name, value: r[name] diff --git a/packages/cloudapi-gql/src/api/packages.js b/packages/cloudapi-gql/src/api/packages.js index 7732abeb..966c2362 100644 --- a/packages/cloudapi-gql/src/api/packages.js +++ b/packages/cloudapi-gql/src/api/packages.js @@ -1,4 +1,5 @@ const request = require('./request'); module.exports.list = ctx => request('listPackages', ctx); -module.exports.get = ctx => request('getPackage', ctx); +module.exports.get = ({ id, name }) => + request.fetch(`/:login/packages/${id || name}`); diff --git a/packages/cloudapi-gql/src/schema/resolvers.js b/packages/cloudapi-gql/src/schema/resolvers.js index ff3dd229..d78e9427 100644 --- a/packages/cloudapi-gql/src/schema/resolvers.js +++ b/packages/cloudapi-gql/src/schema/resolvers.js @@ -40,7 +40,7 @@ const resolvers = { id ? api.packages.get({ id }).then(pkg => [pkg]) : api.packages.list(rest), - package: (root, { id }) => api.packages.get({ id }), + package: (root, { id, name }) => api.packages.get({ id, name }), machines: (root, { id, brand, state, tags, ...rest }) => id ? api.machines.get({ id }).then(machine => [machine]) @@ -103,16 +103,20 @@ const resolvers = { keys: ({ login }, { name }) => resolvers.Query.keys(null, { login, name }) }, Machine: { + brand: ({ brand }) => (brand ? brand.toUpperCase() : brand), state: ({ state }) => (state ? state.toUpperCase() : state), + image: ({ image }) => resolvers.Query.image(null, { id: image }), tags: ({ id }, { name }) => resolvers.Query.tags(null, { machine: id, name }), metadata: ({ id }, { name }) => resolvers.Query.metadata(null, { machine: id, name }), - snapshots: ({ id }, { name }) => - resolvers.Query.snapshots(null, { machine: id, name }), networks: ({ networks }) => Promise.all(networks.map(id => resolvers.Query.network(null, { id }))), // eslint-disable-next-line camelcase + package: (root) => resolvers.Query.package(null, { name: root.package }), + snapshots: ({ id }, { name }) => + resolvers.Query.snapshots(null, { machine: id, name }), + // eslint-disable-next-line camelcase firewall_rules: ({ id: machine }, { id }) => resolvers.Query.firewall_rules(null, { machine, id }), actions: ({ id }) => resolvers.Query.actions(null, { machine: id }) @@ -128,6 +132,7 @@ const resolvers = { }, Caller: { type: ({ type }) => (type ? type.toUpperCase() : type), + // eslint-disable-next-line camelcase key_id: ({ keyId }) => keyId } }; diff --git a/packages/cloudapi-gql/src/schema/schema.graphql b/packages/cloudapi-gql/src/schema/schema.graphql index fde32026..50248afb 100644 --- a/packages/cloudapi-gql/src/schema/schema.graphql +++ b/packages/cloudapi-gql/src/schema/schema.graphql @@ -562,6 +562,8 @@ type Query { package( # The id of for this package id: ID + # The "friendly" name for this package + name: String ): Package # Lists all instances we have on record for your account machines( diff --git a/yarn.lock b/yarn.lock index 9cdc14a0..d267b47a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1180,9 +1180,10 @@ babel-plugin-minify-type-constructors@^0.2.0: babel-helper-is-void-0 "^0.2.0" babel-plugin-styled-components@^1.1.7, babel-plugin-styled-components@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/babel-plugin-styled-components/-/babel-plugin-styled-components-1.2.0.tgz#8bb8f9e69119bb8dee408c8d36a0dfef5191f3c7" + version "1.2.1" + resolved "https://registry.yarnpkg.com/babel-plugin-styled-components/-/babel-plugin-styled-components-1.2.1.tgz#e1593f2a6a0327e2d156695306e60c4dd175866d" dependencies: + babel-types "^6.26.0" stylis "^3.2.1" babel-plugin-syntax-async-functions@^6.8.0: @@ -12737,8 +12738,8 @@ vise@2.x.x: hoek "4.x.x" vlq@^0.2.1: - version "0.2.2" - resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.2.tgz#e316d5257b40b86bb43cb8d5fea5d7f54d6b0ca1" + version "0.2.3" + resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" vm-browserify@0.0.4: version "0.0.4"