query trackers($cursor: Cursor) {
    trackers(cursor: $cursor) {
        ...trackers
    }
}

query trackersByUser($username: String!, $cursor: Cursor) {
    user(username: $username) {
        trackers(cursor: $cursor) {
            ...trackers
        }
    }
}

fragment trackers on TrackerCursor {
    results {
        name
        description
        visibility
    }
    cursor
}

query exportTracker($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            ...trackerExport
        }
    }
}

query exportTrackers($cursor: Cursor) {
    trackers(cursor: $cursor) {
        results {
            ...trackerExport
        }
        cursor
    }
}

fragment trackerExport on Tracker {
    name
    description
    visibility
    export
}

query trackerIDByName($name: String!) {
    me {
        tracker(name: $name) {
            id
        }
    }
}

query trackerIDByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            id
        }
    }
}

query tickets($name: String!, $cursor: Cursor) {
    me {
        tracker(name: $name) {
            tickets(cursor: $cursor) {
                ...tickets
            }
        }
    }
}

query ticketsByUser($username: String!, $name: String!, $cursor: Cursor) {
    user(username: $username) {
        tracker(name: $name) {
            tickets(cursor: $cursor) {
                ...tickets
            }
        }
    }
}

fragment tickets on TicketCursor {
    results {
        id
        subject
        status
        resolution
        created
        submitter {
            canonicalName
        }
        labels {
            name
            backgroundColor
            foregroundColor
        }
    }
    cursor
}

query labels($name: String!, $cursor: Cursor) {
    me {
        tracker(name: $name) {
            labels(cursor: $cursor) {
                ...labels
            }
        }
    }
}

query labelsByUser($username: String!, $name: String!, $cursor: Cursor) {
    user(username: $username) {
        tracker(name: $name) {
            labels(cursor: $cursor) {
                ...labels
            }
        }
    }
}

fragment labels on LabelCursor {
    results {
        name
        backgroundColor
        foregroundColor
    }
    cursor
}

query aclByTrackerName($name: String!, $cursor: Cursor) {
    me {
        tracker(name: $name) {
            ...acl
        }
    }
}

query aclByUser($username: String!, $name: String!, $cursor: Cursor) {
    user(username: $username) {
        tracker(name: $name) {
            ...acl
        }
    }
}

fragment acl on Tracker {
    defaultACL {
        browse
        submit
        comment
        edit
        triage
    }
    acls(cursor: $cursor) {
        results {
            id
            created
            entity {
                canonicalName
            }
            browse
            submit
            comment
            edit
            triage
        }
        cursor
    }
}

query userIDByName($username: String!) {
    user(username: $username) {
        id
    }
}

query assignees($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
        }
    }
}

query assigneesByUser($username: String!, $name: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
        }
    }
}

query completeTicketId($name: String!, $subscription: Boolean!) {
    me {
        tracker(name: $name) {
            ...completeTicket
        }
    }
}

query completeTicketIdByUser(
    $username: String!
    $name: String!
    $subscription: Boolean!
) {
    user(username: $username) {
        tracker(name: $name) {
            ...completeTicket
        }
    }
}

fragment completeTicket on Tracker {
    tickets {
        results {
            id
            subject
            ... on Ticket @include(if: $subscription) {
                subscription {
                    id
                }
            }
        }
    }
}

query completeTicketAssign($name: String!, $id: Int!) {
    me {
        canonicalName
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
            tickets {
                results {
                    assignees {
                        canonicalName
                    }
                }
            }
        }
    }
}

query completeTicketAssignByUser(
    $username: String!
    $name: String!
    $id: Int!
) {
    me {
        canonicalName
    }

    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                assignees {
                    canonicalName
                }
            }
            tickets {
                results {
                    assignees {
                        canonicalName
                    }
                }
            }
        }
    }
}

query trackerNames {
    trackers {
        results {
            name
        }
    }
}

query ticketWebhooks($name: String!, $id: Int!, $cursor: Cursor) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticketWebhooks
            }
        }
    }
}

query ticketWebhooksByUser(
    $username: String!
    $name: String!
    $id: Int!
    $cursor: Cursor
) {
    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticketWebhooks
            }
        }
    }
}

fragment ticketWebhooks on Ticket {
    webhooks(cursor: $cursor) {
        results {
            id
            url
        }
        cursor
    }
}

query userWebhooks($cursor: Cursor) {
    userWebhooks(cursor: $cursor) {
        results {
            id
            url
        }
        cursor
    }
}

query trackerWebhooks($name: String!, $cursor: Cursor) {
    me {
        tracker(name: $name) {
            ...trackerWebhooks
        }
    }
}

query trackerWebhooksByUser(
    $username: String!
    $name: String!
    $cursor: Cursor
) {
    user(username: $username) {
        tracker(name: $name) {
            ...trackerWebhooks
        }
    }
}

fragment trackerWebhooks on Tracker {
    webhooks(cursor: $cursor) {
        results {
            id
            url
        }
        cursor
    }
}

query ticketByName($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                ...ticket
            }
        }
    }
}

query ticketByUser($username: String!, $tracker: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $tracker) {
            ticket(id: $id) {
                ...ticket
            }
        }
    }
}

fragment ticket on Ticket {
    created
    updated
    submitter {
        canonicalName
    }
    subject
    body
    status
    resolution
    labels {
        name
        backgroundColor
        foregroundColor
    }
    assignees {
        canonicalName
    }
    events {
        results {
            created
            changes {
                __typename
                ... on Comment {
                    author {
                        canonicalName
                    }
                    text
                }
            }
        }
    }
}

query ticketBodyByName($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            id
            ticket(id: $id) {
                ...ticketBody
            }
        }
    }
}

query ticketBodyByUser($username: String!, $tracker: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $tracker) {
            id
            ticket(id: $id) {
                ...ticketBody
            }
        }
    }
}

fragment ticketBody on Ticket {
    id
    subject
    body
}

query labelIDByName($trackerName: String!, $labelName: String!) {
    me {
        tracker(name: $trackerName) {
            label(name: $labelName) {
                id
            }
        }
    }
}

query labelIDByUser(
    $username: String!
    $trackerName: String!
    $labelName: String!
) {
    user(username: $username) {
        tracker(name: $trackerName) {
            label(name: $labelName) {
                id
            }
        }
    }
}

query completeLabel($name: String!) {
    me {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }
        }
    }
}

query completeLabelByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }
        }
    }
}

query completeTicketLabel($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }

            ticket(id: $id) {
                labels {
                    name
                }
            }
        }
    }
}

query completeTicketLabelByUser($username: String!, $name: String!, $id: Int!) {
    user(username: $username) {
        tracker(name: $name) {
            labels {
                results {
                    name
                }
            }

            ticket(id: $id) {
                labels {
                    name
                }
            }
        }
    }
}

query completeTicketUnlabel($name: String!, $id: Int!) {
    me {
        tracker(name: $name) {
            ticket(id: $id) {
                labels {
                    name
                }
            }
        }
    }
}

query completeTicketUnlabelByUser(
    $username: String!
    $name: String!
    $id: Int!
) {
    user(username: $username) {
        tracker(name: $name) {
            ticket(id: $id) {
                labels {
                    name
                }
            }
        }
    }
}

query trackerDescription($name: String!) {
    me {
        tracker(name: $name) {
            description
        }
    }
}

query trackerDescriptionByUser($username: String!, $name: String!) {
    user(username: $username) {
        tracker(name: $name) {
            description
        }
    }
}

mutation deleteTracker($id: Int!) {
    deleteTracker(id: $id) {
        name
    }
}

mutation submitComment(
    $trackerId: Int!
    $ticketId: Int!
    $input: SubmitCommentInput!
) {
    submitComment(trackerId: $trackerId, ticketId: $ticketId, input: $input) {
        ticket {
            subject
        }
    }
}

mutation updateTicketStatus(
    $trackerId: Int!
    $ticketId: Int!
    $input: UpdateStatusInput!
) {
    updateTicketStatus(
        trackerId: $trackerId
        ticketId: $ticketId
        input: $input
    ) {
        ticket {
            subject
        }
    }
}

mutation deleteLabel($id: Int!) {
    deleteLabel(id: $id) {
        name
    }
}

mutation createLabel(
    $trackerId: Int!
    $name: String!
    $foregroundColor: String!
    $backgroundColor: String!
) {
    createLabel(
        trackerId: $trackerId
        name: $name
        foregroundColor: $foregroundColor
        backgroundColor: $backgroundColor
    ) {
        name
        backgroundColor
        foregroundColor
    }
}

mutation updateLabel($id: Int!, $input: UpdateLabelInput!) {
    updateLabel(id: $id, input: $input) {
        name
    }
}

mutation deleteACL($id: Int!) {
    deleteACL(id: $id) {
        tracker {
            name
        }
        entity {
            canonicalName
        }
    }
}

mutation trackerSubscribe($trackerId: Int!) {
    trackerSubscribe(trackerId: $trackerId) {
        tracker {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation trackerUnsubscribe($trackerId: Int!) {
    # TODO: Wait for API to implement "tickets"
    trackerUnsubscribe(trackerId: $trackerId, tickets: false) {
        tracker {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation ticketSubscribe($trackerId: Int!, $ticketId: Int!) {
    ticketSubscribe(trackerId: $trackerId, ticketId: $ticketId) {
        ticket {
            id
        }
    }
}

mutation ticketUnsubscribe($trackerId: Int!, $ticketId: Int!) {
    ticketUnsubscribe(trackerId: $trackerId, ticketId: $ticketId) {
        ticket {
            id
        }
    }
}

mutation assignUser($trackerId: Int!, $ticketId: Int!, $userId: Int!) {
    assignUser(trackerId: $trackerId, ticketId: $ticketId, userId: $userId) {
        ticket {
            subject
        }
    }
}

mutation unassignUser($trackerId: Int!, $ticketId: Int!, $userId: Int!) {
    unassignUser(trackerId: $trackerId, ticketId: $ticketId, userId: $userId) {
        ticket {
            subject
        }
    }
}

mutation createTracker(
    $name: String!
    $description: String
    $visibility: Visibility!
) {
    createTracker(
        name: $name
        description: $description
        visibility: $visibility
    ) {
        name
    }
}

mutation importTracker(
    $name: String!
    $description: String
    $visibility: Visibility!
    $dump: Upload!
) {
    createTracker(
        name: $name
        description: $description
        visibility: $visibility
        importUpload: $dump
    ) {
        id
    }
}

mutation deleteTicket($trackerId: Int!, $ticketId: Int!) {
    deleteTicket(trackerId: $trackerId, ticketId: $ticketId) {
        subject
    }
}

mutation createTicketWebhook(
    $trackerId: Int!
    $ticketId: Int!
    $config: TicketWebhookInput!
) {
    createTicketWebhook(
        trackerId: $trackerId
        ticketId: $ticketId
        config: $config
    ) {
        id
    }
}

mutation deleteTicketWebhook($id: Int!) {
    deleteTicketWebhook(id: $id) {
        id
    }
}

mutation createUserWebhook($config: UserWebhookInput!) {
    createUserWebhook(config: $config) {
        id
    }
}

mutation deleteUserWebhook($id: Int!) {
    deleteUserWebhook(id: $id) {
        id
    }
}

mutation createTrackerWebhook($trackerId: Int!, $config: TrackerWebhookInput!) {
    createTrackerWebhook(trackerId: $trackerId, config: $config) {
        id
    }
}

mutation deleteTrackerWebhook($id: Int!) {
    deleteTrackerWebhook(id: $id) {
        id
    }
}

mutation submitTicket($trackerId: Int!, $input: SubmitTicketInput!) {
    submitTicket(trackerId: $trackerId, input: $input) {
        id
    }
}

mutation labelTicket($trackerId: Int!, $ticketId: Int!, $labelId: Int!) {
    labelTicket(trackerId: $trackerId, ticketId: $ticketId, labelId: $labelId) {
        ticket {
            subject
        }
    }
}

mutation unlabelTicket($trackerId: Int!, $ticketId: Int!, $labelId: Int!) {
    unlabelTicket(
        trackerId: $trackerId
        ticketId: $ticketId
        labelId: $labelId
    ) {
        ticket {
            subject
        }
    }
}

mutation updateTicket(
    $trackerId: Int!
    $ticketId: Int!
    $input: UpdateTicketInput!
) {
    updateTicket(trackerId: $trackerId, ticketId: $ticketId, input: $input) {
        id
    }
}

mutation updateTracker($id: Int!, $input: TrackerInput!) {
    updateTracker(id: $id, input: $input) {
        name
    }
}

mutation clearDescription($id: Int!) {
    updateTracker(id: $id, input: { description: null }) {
        name
    }
}
