How to update when field xyz="something" on graphql queries instead of updating by id

System Information
  • Strapi Version: 3.1.4
  • Operating System: Kali Linux
  • Database: Postgresql
  • Node Version: 12.18.3
  • NPM Version: 6.14.6
  • Yarn Version:

I’m using strapi with the graphql plugin. I would like to update a type by searching for its “uname” field. As of now, It seems I can only search for ids, not some other field. Given below are the code snippets. First one is working, but the second one isn’t.

mutation {
  updateTodoer(input:{where: {id:"randomgibbrish"}}) {
    todoer {
      uname, todos{text}
    }
  }
}
mutation {
  updateTodoer(input:{where: {uname:"hello"}}) {
    todoer {
      uname, todos{text}
    }
  }
}

Currently our resolvers don’t handle this type of request (as it’s largely based on our REST implementation) though this will be changing in the future. In your case it would require a custom resolver or at least a customization of the currently implemented one.

Let me ping @alexandrebodin @Convly and @Pierre_Noel to see if they have any suggestions.

Found the solution(or should I say workaround). That is to first query for finding the id, then use that id to update the type. Shown below is an example. From the first query we get the id, using that we update the type on the second query. As far as my understanding goes, Updating the type by searching for fields is a two step process, you find the thing, and then you update the thing(I might be wrong). But the benefit of directly updating the type without going through finding the thing manually is that you save an extra query. And in my opinion, graphql is all about efficiency. Would love to have it all combined togther in the future. As of now, here is the solution.

query {  // This gives us the id back
	todoers(where: {uname_contains:"y"}) {
    id 
  }
}

mutation {  // Use the id found from previous queries
  updateTodoer(input:{where:{id:5}, data:{uname:"something"}}) {
    todoer {
      uname, pass, id   
    }
  }
}

Can you give a barebones example of customizing the resolver in the ‘strapi way’, so that it answers the question?