How do I write a graphQL mutation in a python function?

I want to create a python function of a simple graphQL mutation. I have a graphQL schema and there is a mutation to delete an object by giving its ID.
GraphQL docs shows :

delete(
id: ID!
): Boolean!

To delete the object using the global ID I tried creating a python function but I am getting a syntax error of graphQL which I am not able to figure out.

#function to delete FIB
def deleteObj(self,id): # returns FIB deletion boolean
    
        objDel = self.graphQLClient.fetch("""
            mutation delete($id: [ID!]!) {
                delete(id: $id,) {
                    id
                }
            }
        """, {
            'id': id ,
            
        })
        info('***Object deletion result %sn' % objDel)

I am able to understand I am doing some silly mistake but an explanation would help me in the future.

Error I am getting is:

fib deletion result {‘data’: None, ‘errors’: [{‘message’: ‘Syntax
Error GraphQL request (3:34) Unexpected empty IN {}nn2:
mutation delete($id: [ID!]!) {n3: delete(id: $id,)
{n ^n4: n’, ‘locations’:
[{‘line’: 3, ‘column’: 34}]}]}

I am able to insert an object using mutation something like this:

def insertFibEntry(self, prefix, name): # returns FIB entry ID
        
        fib = self.graphQLClient.fetch("""
            mutation insertFibEntry($name: Name!, $nexthops: [ID!]!) {
                insertFibEntry(name: $name, nexthops: $nexthops) {
                    id
                }
            }
        """, {
            'name': "/"+prefix ,
            'nexthops': [self.faces[name]['data']['createFace']['id']]
            
        })
        info('***fib result %sn' % fib)
        info('***prefix is %s'% "'/"+prefix+"'"+ 'n')

Read more here: Source link