Skip to content

a8n: GraphQL API for draft campaigns

Warren Gifford requested to merge a8n/draft-mode-api into master

Created by: mrnugget

This adds the GraphQL API necessary for #7217 (closed). 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:

  1. Create a Campaign as a draft: createCampaign with draft = 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.

  1. Publish 1/2 of the changesetPlans:
mutation PublishChangesetPlan($id: ID!) {
  publishChangesetPlan(changesetPlan: $id) {
    alwaysNil
  }
}

Variables:

{
  "id":"Q2hhbmdlc2V0UGxhbjoyNjU3"
}

Response:

{
  "data": {
    "publishChangesetPlan": {
      "alwaysNil": null
    }
  }
}
  1. Query the Campaign to see that one changesetPlan has been turned into a changeset:
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"
          }
        ]
      }
    }
  }
}
  1. Publish the complete campaign:
mutation PublishCampaign($id: ID!) {
  publishCampaign(campaign: $id) {
    id
  }
}

Response:

{
  "data": {
    "node": {
      "id": "Q2FtcGFpZ246OQ=="
    }
  }
}
  1. 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.

Merge request reports

Loading