GraphQL adding and removing items

When adding certain items using createProjectMedia, I get the following error:

{'code': 9, 'data': {'id': 390929, 'project_id': 3111, 'type': 'media', 'url': 'https://checkmedia.org/ischool-hrc/project/3111/media/390929'}, 'message': 'This item already exists'}

However, when the item is trashed using updateProjectMedia to test the function, it does not actually delete. How can trashed items be removed completely? (and on a side note, what exactly is the function of destroyProjectMedia?)

Hi Vyoma!

This happens because the URL was already added to this team. The url you get on response is the link for the existent item on your team.

When you send archived: 1 on updateProjectMedia you are only sending the item to trash. The item will still be on the team and if the same URL is sent again you’ll receive the error message you mentioned: 'This item already exists'

To actually remove the item you should use destroyProjectMedia. You can see an example of how to send the mutation in the Wiki: GraphQL query examples · meedan/check Wiki · GitHub

1 Like

Hi Daniela, thanks so much for the reply! I’m working on the same project as Vyoma above and we have moved to destroyProjectMedia. However, we are now receiving the following errors:

{'code': 5, 'data': {}, 'message': "undefined method project’ for #Link:0x000055a25eb74cc8\nDid you mean? projects\n projects="}`

and

{‘code’: 5, ‘data’: {}, ‘message’: ‘No permission to delete Dynamic’}`

Do you have any advice on how we can resolve this issues?

Hi Nicole, welcome to our community!

I need more info to help you with these errors.
For some items you are trying to delete you receive the first error and for other items you receive the other error?
Could you delete any item?
Can you paste here the mutation you are sending, please?

This was the first query I ran:

mutation {
              destroyProjectMedia(input: {
                clientMutationId: "1",
                id: "UHJvamVjdE1lZGlhLzM5MTc1OQ==\n"
              }) { deletedId }
            }

to which I received this error:

{
  "errors": [
    {
      "code": 5,
      "data": {},
      "message": "No permission to delete Dynamic"
    }
  ]
}

This was the second query I ran:

mutation {
              destroyProjectMedia(input: {
                clientMutationId: "1",
                id: "TWVkaWEvMzc4Njgw\n"
              }) { deletedId }
            }

to which I received this error:

{
  "errors": [
    {
      "code": 5,
      "data": {},
      "message": "undefined method `project' for #<Link:0x00007f34c5919af0>\nDid you mean?  projects\n               projects="
    }
  ]
}

Most items I attempt to delete lead to the second error and I attempted these mutations on both archived and non-archived items.

Hi Nicole,

The query raises the error "No permission to delete Dynamic" when it thinks you don’t have permission to execute the query. As you are a team owner, you should be able to do this. It looks like a bug. I reported this error and I will notify here when it is fixed.

The other error message is displayed when the id you send is not from a ProjectMedia. You probably got the media id instead of the project_media. Can you verify if this is the case, please?

Hi Daniela,

That is indeed the case for the "undefined method project" error. Thank you!

Also, I was experimenting with mutations and figured out how to bypass the "No permission to delete Dynamic". Like with updateProjectMedia, it appears that single queries for destroyProjectMedia require both id and ids fields to be filled out even when trashing individual items:

However, even when the mutation is successful, nothing seems to be happening. We are trying to destroy the first item in the below query, but before and after running the above mutation the item is still there. Our query to add items also gives the "This item already exists" error when we attempt to add the item after an error-free mutation. Unless there is a delay of more than a few minutes in performing the mutation, I don’t know what would cause this.

Hi Vyoma,

Good to know that was the case for the second error!

The destroyProjectMedia mutation accepts both queries:

  • only sending the id to delete a single item;
  • sending ids with a list of items to delete and the id that should be one of the list
    • This one is deprecated, soon this mutation won’t accept ids, you should not get used to this one.

As you can see in your second image, the item you are trying to destroy has archive: true. For now is not possible to send the destroyProjectMedia mutation for archived items.
Just to check if this is the only problem, could you try the mutation with a not-archived item?

Hi Daniela,

Using a non-archived item appears to have worked! And also thanks for the heads up about ids - we’ll be sure to change our queries accordingly. Appreciate your help :slight_smile:

1 Like