GraphQL API Deployment #3344
-
What's the comand for deploying graphql APIs to different workspaces in V3? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hi @AmeyGohil! As you suggested, this seems to be missing from our documentation indeed - I will make a note for us to add it. You should be able to deploy your GraphQL APIs by specifying the different workspaces in your
Please note that specifying multiple workspaces means GraphQL APIs will be deployed for each of them when you run the Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
@AmeyGohil I realize I was a bit hasty in my answer, and didnt provide an example! Sorry about that. // sanity.cli.ts
import { createCliConfig } from "sanity/cli";
/**
* Adds support for --workspace=<workspaceId>
*
* Can be provided multiple times to include more workspaces
*/
function getWorkspaceFilter(): string[] {
// get at the npm arguments -> clean it up a bit along the way
const args = (process.env.npm_lifecycle_script ?? "")
.split(" ")
.map((arg) => arg.replace(/['"]/g, ""));
return args
.filter((arg) => arg.startsWith("--workspace="))
.map((arg) => arg.split("=")[1]);
}
const workspaceFilter = getWorkspaceFilter();
/* examples commands:
# Deploy all workspaces
npx sanity graphql deploy
# Deploy single workspace
npx sanity graphql deploy --workspace=staging
# Deploy multiple workspace
npx sanity graphql deploy --workspace=staging --workspace=preprod
*/
export default createCliConfig({
api: {
projectId: "<PROJECT_ID>",
dataset: "<DATASET_NAME>",
},
graphql: [
{ workspace: "default" },
{ workspace: "staging" },
{ workspace: "preprod" },
].filter((gqlConfig) =>
workspaceFilter.length
? workspaceFilter.includes(gqlConfig.workspace)
: true
),
}); This adds a bit of code to get the original CLI command, parses it and extracts filters for workspace. With this approach you can make the cli do anything with your config object really, based on any command line argument you desire ;) |
Beta Was this translation helpful? Give feedback.
-
Thanks for raising, @AmeyGohil - we are working on a native solution for this - adding a Might not see a release before next week, however. |
Beta Was this translation helpful? Give feedback.
-
v3.0.0-dev-preview.10 is out and includes the You can now set an // sanity.cli.ts
import {createCliConfig} from 'sanity/cli'
export default createCliConfig({
api: {
projectId: <PROJECT_ID>,
dataset: <DATASET_NAME>,
},
graphql: [
{
id: 'production',
workspace: 'default',
},
{
id: 'staging',
workspace: 'staging',
},
],
}) The
|
Beta Was this translation helpful? Give feedback.
v3.0.0-dev-preview.10 is out and includes the
--api
flag 👍You can now set an
id
on GraphQL APIs in yoursanity.cli.ts
:The
id
is used in combination with the--api
flag: