Skip to content

Commit

Permalink
[core] GraphQL: Add a tag option when interacting with GraphQL endpoi…
Browse files Browse the repository at this point in the history
…nts (#1606)
  • Loading branch information
saasen committed Feb 27, 2020
1 parent 31f3f11 commit 0ce072f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/@sanity/core/src/actions/graphql/deleteApiAction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = async function deleteApiAction(args, context) {
const {apiClient, output, prompt} = context
const flags = args.extOptions

const client = apiClient({
requireUser: true,
Expand All @@ -16,10 +17,11 @@ module.exports = async function deleteApiAction(args, context) {
return
}

const dataset = client.config().dataset
const dataset = flags.dataset || client.config().dataset
const tag = flags.tag || 'default'
try {
await client.request({
url: `/apis/graphql/${dataset}/default`,
url: `/apis/graphql/${dataset}/${tag}`,
method: 'DELETE'
})
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/core/src/actions/graphql/deployApiAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = async function deployApiActions(args, context) {
})

const dataset = flags.dataset || client.config().dataset
const tag = flags.tag || 'default'
const enablePlayground =
typeof flags.playground === 'undefined'
? await prompt.single({
Expand Down Expand Up @@ -53,7 +54,7 @@ module.exports = async function deployApiActions(args, context) {

try {
const response = await client.request({
url: `/apis/graphql/${dataset}/default`,
url: `/apis/graphql/${dataset}/${tag}`,
method: 'PUT',
body: {enablePlayground, schema},
maxRedirects: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import lazyRequire from '@sanity/util/lib/lazyRequire'

const helpText = `
Options
--dataset <dataset> Delete GraphQL API for the given dataset
--tag <tag> Delete GraphQL API for the given tag (defaults to 'default')
Examples
sanity graphql undeploy
sanity graphql undeploy --dataset staging
sanity graphql undeploy --dataset staging --tag next
`

export default {
name: 'undeploy',
group: 'graphql',
description: 'Remove a deployed GraphQL API',
action: lazyRequire(require.resolve('../../actions/graphql/deleteApiAction'))
action: lazyRequire(require.resolve('../../actions/graphql/deleteApiAction')),
helpText
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import lazyRequire from '@sanity/util/lib/lazyRequire'
const helpText = `
Options
--dataset <dataset> Deploy API for the given dataset
--tag <tag> Deploy API to given tag (defaults to 'default')
--playground Deploy a GraphQL playground for easily testing queries (public)
--no-playground Skip playground prompt (do not deploy a playground)
Examples
sanity graphql deploy
sanity graphql deploy --playground
sanity graphql deploy --dataset staging --no-playground
sanity graphql deploy --dataset staging --tag next --no-playground
`

export default {
Expand Down

0 comments on commit 0ce072f

Please sign in to comment.