Api ReferenceGraphqlMerge Requests

Merge Requests (GraphQL)

Query and manage merge requests, reviews, and comments via GraphQL.

The GraphQL API provides full access to merge request data — status, reviews, comments, pipeline results, and merge operations.

Merge Request Object

type MergeRequest {
  id: ID!
  number: Int!
  title: String!
  description: String
  state: MergeRequestState!  # OPEN, MERGED, CLOSED
  draft: Boolean!
  author: User!
  sourceBranch: String!
  targetBranch: String!
  createdAt: DateTime!
  updatedAt: DateTime!
  mergedAt: DateTime
  mergedBy: User
  url: String!
 
  # Connections
  reviews(first: Int, after: String): ReviewConnection!
  comments(first: Int, after: String): CommentConnection!
  commits(first: Int, after: String): CommitConnection!
  files(first: Int, after: String): DiffFileConnection!
  labels: [Label!]!
  assignees: [User!]!
  reviewers: [User!]!
  pipeline: Pipeline
  checklist: ReviewChecklist
}
 
enum MergeRequestState {
  OPEN
  MERGED
  CLOSED
}

Queries

List Merge Requests

query {
  repository(owner: "my-org", name: "my-repo") {
    mergeRequests(
      first: 20
      state: OPEN
      orderBy: { field: UPDATED_AT, direction: DESC }
    ) {
      nodes {
        number
        title
        author { username avatarUrl }
        sourceBranch
        targetBranch
        createdAt
        updatedAt
        draft
        labels { name color }
        reviewers { username }
        pipeline { status }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
      totalCount
    }
  }
}

Get Merge Request Details

query {
  repository(owner: "my-org", name: "my-repo") {
    mergeRequest(number: 42) {
      title
      description
      state
      author { username }
      sourceBranch
      targetBranch
      createdAt
      mergedAt
      mergedBy { username }
 
      # Review status
      reviews {
        nodes {
          author { username }
          state  # APPROVED, CHANGES_REQUESTED, COMMENTED
          submittedAt
          body
        }
      }
 
      # Changed files
      files {
        nodes {
          path
          status
          additions
          deletions
        }
        totalCount
      }
 
      # Inline comments
      comments {
        nodes {
          author { username }
          body
          path
          line
          createdAt
          resolved
          replies {
            nodes {
              author { username }
              body
              createdAt
            }
          }
        }
      }
 
      # Pipeline status
      pipeline {
        status
        stages {
          nodes {
            name
            status
            duration
          }
        }
      }
 
      # Review checklist
      checklist {
        items {
          title
          checked
          checkedBy { username }
        }
        completionPercentage
      }
 
      # Merge readiness
      mergeable
      mergeBlockers {
        type  # REVIEW_REQUIRED, STATUS_CHECK, CONFLICT, DRAFT
        description
      }
    }
  }
}

Get Merge Request Diff

query {
  repository(owner: "my-org", name: "my-repo") {
    mergeRequest(number: 42) {
      files(first: 100) {
        nodes {
          path
          previousPath  # if renamed
          status  # ADDED, MODIFIED, DELETED, RENAMED
          additions
          deletions
          hunks {
            header
            lines {
              type  # ADDITION, DELETION, CONTEXT
              number
              content
            }
          }
        }
      }
    }
  }
}

Mutations

Create Merge Request

mutation {
  createMergeRequest(input: {
    repositoryId: "repo_01H8XYZ"
    title: "Implement token refresh"
    description: "Adds automatic token refresh with configurable TTL.\n\nCloses #15"
    sourceBranch: "feature/token-refresh"
    targetBranch: "main"
    draft: false
    labels: ["backend", "security"]
    reviewers: ["alice", "bob"]
    assignees: ["charlie"]
  }) {
    mergeRequest {
      number
      url
    }
  }
}

Update Merge Request

mutation {
  updateMergeRequest(input: {
    mergeRequestId: "mr_01H8XYZ"
    title: "Implement token refresh with TTL"
    description: "Updated description"
    labels: ["backend", "security", "reviewed"]
    assignees: ["charlie", "dave"]
  }) {
    mergeRequest {
      number
      title
      labels { name }
    }
  }
}

Submit Review

mutation {
  submitReview(input: {
    mergeRequestId: "mr_01H8XYZ"
    state: APPROVED
    body: "Looks good. The error handling is solid."
    comments: [
      {
        path: "src/auth/token.rs"
        line: 42
        body: "Consider adding a doc comment here explaining the TTL behavior."
      }
    ]
  }) {
    review {
      id
      state
      submittedAt
    }
  }
}

Merge

mutation {
  mergeMergeRequest(input: {
    mergeRequestId: "mr_01H8XYZ"
    strategy: SQUASH  # MERGE, SQUASH, REBASE
    commitMessage: "Implement token refresh with TTL (#42)"
    deleteSourceBranch: true
  }) {
    mergeRequest {
      state
      mergedAt
      mergedBy { username }
    }
  }
}

Add Comment

mutation {
  addMergeRequestComment(input: {
    mergeRequestId: "mr_01H8XYZ"
    body: "What about the edge case where the token is already expired?"
    path: "src/auth/token.rs"
    line: 55
  }) {
    comment {
      id
      createdAt
    }
  }
}

Resolve Thread

mutation {
  resolveThread(input: {
    commentId: "cmt_01H8XYZ"
  }) {
    comment {
      resolved
      resolvedBy { username }
    }
  }
}

Close Merge Request

mutation {
  closeMergeRequest(input: {
    mergeRequestId: "mr_01H8XYZ"
  }) {
    mergeRequest {
      state
    }
  }
}