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

query mailingLists($cursor: Cursor) {
    me {
        lists(cursor: $cursor) {
            ...lists
        }
    }
}

query exportMailingList($username: String!, $name: String!) {
    user(username: $username) {
        list(name: $name) {
            ...mailingListExport
        }
    }
}

query exportMailingLists($cursor: Cursor) {
    me {
        lists(cursor: $cursor) {
            results {
                ...mailingListExport
            }
            cursor
        }
    }
}

fragment mailingListExport on MailingList {
    name
    description
    visibility
    permitMime
    rejectMime
    archive
}

query mailingListsByUser($username: String!, $cursor: Cursor) {
    user(username: $username) {
        lists(cursor: $cursor) {
            ...lists
        }
    }
}

fragment lists on MailingListCursor {
    results {
        name
        description
        visibility
    }
    cursor
}

query mailingListIDByName($name: String!) {
    me {
        list(name: $name) {
            id
        }
    }
}

query mailingListIDByUser($username: String!, $name: String!) {
    user(username: $username) {
        list(name: $name) {
            id
        }
    }
}

query listPatches($name: String!, $cursor: Cursor) {
    me {
        list(name: $name) {
            ...patchsetsByList
        }
    }
}

query listPatchesByUser($username: String!, $name: String!, $cursor: Cursor) {
    user(username: $username) {
        list(name: $name) {
            ...patchsetsByList
        }
    }
}

fragment patchsetsByList on MailingList {
    patches(cursor: $cursor) {
        results {
            id
            subject
            status
            created
            version
            prefix
            submitter {
                canonicalName
            }
        }
        cursor
    }
}

query patches($cursor: Cursor) {
    me {
        ...patchsets
    }
}

query patchesByUser($username: String!, $cursor: Cursor) {
    user(username: $username) {
        ...patchsets
    }
}

fragment patchsets on User {
    patches(cursor: $cursor) {
        results {
            id
            subject
            status
            created
            version
            prefix
            list {
                name
                owner {
                    canonicalName
                }
            }
        }
        cursor
    }
}

query patchsetById($id: Int!, $cursor: Cursor) {
    patchset(id: $id) {
        patches(cursor: $cursor) {
            results {
                date
                body
                subject
                header(want: "From")
            }
            cursor
        }
    }
}

query completePatchsetId($name: String!) {
    me {
        list(name: $name) {
            ...completePatchset
        }
    }
}

query completePatchsetIdByUser($username: String!, $name: String!) {
    user(username: $username) {
        list(name: $name) {
            ...completePatchset
        }
    }
}

fragment completePatchset on MailingList {
    patches {
        results {
            id
            subject
            status
            version
            prefix
        }
    }
}

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

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

fragment acl on User {
    list(name: $name) {
        defaultACL {
            browse
            reply
            post
            moderate
        }
        acl(cursor: $cursor) {
            results {
                id
                created
                entity {
                    canonicalName
                }
                browse
                reply
                post
                moderate
            }
            cursor
        }
    }
}

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

query archive($name: String!) {
    me {
        list(name: $name) {
            archive
        }
    }
}

query archiveByUser($username: String!, $name: String!) {
    user(username: $username) {
        list(name: $name) {
            archive
        }
    }
}

query completeLists {
    me {
        lists {
            results {
                name
            }
        }
    }
}

query mailingListWebhooks($name: String!, $cursor: Cursor) {
    me {
        list(name: $name) {
            ...mailingListWebhooks
        }
    }
}

query mailingListWebhooksByUser(
    $username: String!
    $name: String!
    $cursor: Cursor
) {
    user(username: $username) {
        list(name: $name) {
            ...mailingListWebhooks
        }
    }
}

fragment mailingListWebhooks on MailingList {
    webhooks(cursor: $cursor) {
        results {
            id
            url
        }
        cursor
    }
}

query subscriptions($cursor: Cursor) {
    subscriptions(cursor: $cursor) {
        results {
            created
            __typename
            ... on MailingListSubscription {
                list {
                    name
                    owner {
                        canonicalName
                    }
                }
            }
        }
        cursor
    }
}

query mailingListDescription($name: String!) {
    me {
        list(name: $name) {
            description
        }
    }
}

query mailingListDescriptionByUser($username: String!, $name: String!) {
    user(username: $username) {
        list(name: $name) {
            description
        }
    }
}

mutation mailingListSubscribe($listID: Int!) {
    mailingListSubscribe(listID: $listID) {
        list {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation mailingListUnsubscribe($listID: Int!) {
    mailingListUnsubscribe(listID: $listID) {
        list {
            name
            owner {
                canonicalName
            }
        }
    }
}

mutation updatePatchset($id: Int!, $status: PatchsetStatus!) {
    updatePatchset(id: $id, status: $status) {
        submitter {
            canonicalName
        }
        subject
    }
}

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

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

mutation updateMailingList($id: Int!, $input: MailingListInput!) {
    updateMailingList(id: $id, input: $input) {
        id
    }
}

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

mutation importMailingListSpool($id: Int!, $spool: Upload!) {
    importMailingListSpool(listID: $id, spool: $spool)
}

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

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

mutation createMailingListWebhook(
    $listId: Int!
    $config: MailingListWebhookInput!
) {
    createMailingListWebhook(listId: $listId, config: $config) {
        id
    }
}

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