Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mutation for multiple items #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

olegkron
Copy link

@olegkron olegkron commented Apr 5, 2023

Added a function which allows to modify multiple items at once using graphQL's mutation query.
The function takes a list of dictionaries with methods and any additional parameters the method requires.

This already saved me hours when working with large sets of data, as the only way to work with multiple items with this library was to call the update/create functions one by one, whereas now you're able to perform multiple operations at once.

Hope you find it as much of a lifesaver too!

items_data = [
    {
        "method": "create_item",
        "board_id": 1437462152,
        "group_id": "new_group",
        "item_name": "New Item",
        "column_values": {"status": "done"},
        "create_labels_if_missing": True
    },
    {
        "method": "change_multiple_column_values",
        "board_id": 1435323152,
        "item_id": 1345543264,
        "column_values": {"status": "done"},
        "create_labels_if_missing": True
    }
]

response = monday.items.mutate_multiple_items(items_data)

@olegkron
Copy link
Author

Hi @chdastolfo, please let me know if there's time to review this pull request. Thanks!

Copy link
Collaborator

@chdastolfo chdastolfo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! This looks good, but could you please add test(s) for this as well? It would be good, for example, to make sure this query looks right for various lengths of if the item_data array (length, 1, >1).

@@ -401,7 +431,7 @@ def get_columns_by_board_query(board_ids):
}''' % board_ids


def create_board_by_workspace_query(board_name: str, board_kind: BoardKind, workspace_id = None) -> str:
def create_board_by_workspace_query(board_name: str, board_kind: BoardKind, workspace_id=None) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@@ -59,6 +59,37 @@ def mutate_subitem_query(parent_item_id, subitem_name, column_values,
str(create_labels_if_missing).lower())


def mutate_multiple_items_query(items_data):
Copy link
Collaborator

@chdastolfo chdastolfo Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer item_data, and data as it is more grammatically correct than items_data and item_data. I think the function name makes it clear that the function acts on multiple items.

@chdastolfo
Copy link
Collaborator

Also! Please add this method to the docs in docs/README.rst

@danielcherrington
Copy link

danielcherrington commented Jul 4, 2024

@chdastolfo Being able to group mutations/queries is a really useful feature. Are there any plans for this PR to make it into a release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants