a8n: GraphQL API for draft campaigns
Created by: mrnugget
This adds the GraphQL API necessary for #7217. It implements the API as proposed in this comment with a few minor changes that I discussed with @eseliger, in order to make the client implementation easier.
The API flow for creating a Campaign
in draft mode (that is: without creating pull requests on the code host) is this:
- Create a
Campaign
as a draft:createCampaign
withdraft = true
:
mutation CreateDraftCampaignWithPlan($input: CreateCampaignInput!) {
createCampaign(input: $input) {
id
name
description
publishedAt
changesetCreationStatus {
state
completedCount
pendingCount
errors
}
changesets {
totalCount
}
changesetPlans {
totalCount
nodes {
id
}
}
}
}
Variables:
{
"input":{
"namespace":"VXNlcjox",
"name":"This is a draft campaign",
"description":"This is another cool campaign before release",
"plan": "Q2FtcGFpZ25QbGFuOjUy",
"draft": true
}
}
Response:
{
"data": {
"createCampaign": {
"id": "Q2FtcGFpZ246OQ==",
"name": "This is a draft campaign",
"description": "This is another cool campaign before release",
"publishedAt": null,
"changesetCreationStatus": {
"state": "COMPLETED",
"completedCount": 0,
"pendingCount": 0,
"errors": []
},
"changesets": {
"totalCount": 0
},
"changesetPlans": {
"totalCount": 2,
"nodes": [
{
"id": "Q2hhbmdlc2V0UGxhbjoyNjU3"
},
{
"id": "Q2hhbmdlc2V0UGxhbjoyNjU4"
}
]
}
}
}
}
Note: We have 2
changesetPlans
and publishedAt
is null
.
- Publish 1/2 of the
changesetPlans
:
mutation PublishChangesetPlan($id: ID!) {
publishChangesetPlan(changesetPlan: $id) {
alwaysNil
}
}
Variables:
{
"id":"Q2hhbmdlc2V0UGxhbjoyNjU3"
}
Response:
{
"data": {
"publishChangesetPlan": {
"alwaysNil": null
}
}
}
- Query the Campaign to see that one
changesetPlan
has been turned into achangeset
:
query CampaignStatus($id: ID!) {
node(id: $id) {
... on Campaign {
id
name
description
publishedAt
changesetCreationStatus {
state
completedCount
pendingCount
errors
}
changesets {
totalCount
}
changesetPlans {
totalCount
nodes {
id
}
}
}
}
}
Response:
{
"data": {
"node": {
"id": "Q2FtcGFpZ246OQ==",
"name": "This is a draft campaign",
"description": "This is another cool campaign before release",
"publishedAt": null,
"changesetCreationStatus": {
"state": "COMPLETED",
"completedCount": 1,
"pendingCount": 0,
"errors": []
},
"changesets": {
"totalCount": 1
},
"changesetPlans": {
"totalCount": 1,
"nodes": [
{
"id": "Q2hhbmdlc2V0UGxhbjoyNjU3"
}
]
}
}
}
}
- Publish the complete campaign:
mutation PublishCampaign($id: ID!) {
publishCampaign(campaign: $id) {
id
}
}
Response:
{
"data": {
"node": {
"id": "Q2FtcGFpZ246OQ=="
}
}
}
- Query the CampaignStatus:
Response:
{
"data": {
"node": {
"id": "Q2FtcGFpZ246OQ==",
"name": "This is a draft campaign",
"description": "This is another cool campaign before release",
"publishedAt": "2019-12-19T08:45:14Z",
"changesetCreationStatus": {
"state": "COMPLETED",
"completedCount": 2,
"pendingCount": 0,
"errors": []
},
"changesets": {
"totalCount": 2
},
"changesetPlans": {
"totalCount": 0,
"nodes": []
}
}
}
}
Note we now have 2
changesets
and 0
changesetPlans
.