{"action":"created","issue":{"url":"https://api.github.com/repos/mirumee/saleor/issues/3126","repository_url":"https://api.github.com/repos/mirumee/saleor","labels_url":"https://api.github.com/repos/mirumee/saleor/issues/3126/labels{/name}","comments_url":"https://api.github.com/repos/mirumee/saleor/issues/3126/comments","events_url":"https://api.github.com/repos/mirumee/saleor/issues/3126/events","html_url":"https://github.com/mirumee/saleor/issues/3126","id":371078671,"node_id":"MDU6SXNzdWUzNzEwNzg2NzE=","number":3126,"title":"How to update the model where id is not necessary? ","user":{"login":"MilanRgm","id":17469150,"node_id":"MDQ6VXNlcjE3NDY5MTUw","avatar_url":"https://avatars0.githubusercontent.com/u/17469150?v=4","gravatar_id":"","url":"https://api.github.com/users/MilanRgm","html_url":"https://github.com/MilanRgm","followers_url":"https://api.github.com/users/MilanRgm/followers","following_url":"https://api.github.com/users/MilanRgm/following{/other_user}","gists_url":"https://api.github.com/users/MilanRgm/gists{/gist_id}","starred_url":"https://api.github.com/users/MilanRgm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MilanRgm/subscriptions","organizations_url":"https://api.github.com/users/MilanRgm/orgs","repos_url":"https://api.github.com/users/MilanRgm/repos","events_url":"https://api.github.com/users/MilanRgm/events{/privacy}","received_events_url":"https://api.github.com/users/MilanRgm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-17T13:35:04Z","updated_at":"2018-10-17T14:21:21Z","closed_at":null,"author_association":"NONE","body":"I am trying to use its graphql based api but I have a doubt on the update part. I am not quite sure, so i am asking first on how you are handling the update part where id is not necessary? Like for updating the user profile, id is not necessary, we can get the requested user(info.context.user) and update the items.\r\n\r\nHere is an example\r\n\r\n```python\r\nclass Profile(models.Model):\r\n\r\n    user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, related_name='profile')\r\n    # Introduction\r\n    bio = models.TextField(blank=True, validators=[MaxLengthValidator(1000)],\r\n                           help_text='No more than 1000 characters')\r\n    website = models.URLField(blank=True)\r\n    avatar = models.ImageField(null=True, blank=True,\r\n                               upload_to=get_upload_file_name)\r\n```\r\n\r\n```python\r\nclass ProfileUpdate(ModelMutation):\r\n    class Arguments:\r\n       # id = graphene.ID(description='ID of address to update', required=True) # this is not necessary\r\n        input = ProfileInput(\r\n            description='Fields required to update profile', required=True)\r\n\r\n    class Meta:\r\n        description = 'Updates Profile'\r\n        model = models.Profile\r\n```\r\n\r\nIf i don't provide id, the update does not work, it works as a create view instead of update view. How should i handle such case? "},"comment":{"url":"https://api.github.com/repos/mirumee/saleor/issues/comments/430648192","html_url":"https://github.com/mirumee/saleor/issues/3126#issuecomment-430648192","issue_url":"https://api.github.com/repos/mirumee/saleor/issues/3126","id":430648192,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDY0ODE5Mg==","user":{"login":"MilanRgm","id":17469150,"node_id":"MDQ6VXNlcjE3NDY5MTUw","avatar_url":"https://avatars0.githubusercontent.com/u/17469150?v=4","gravatar_id":"","url":"https://api.github.com/users/MilanRgm","html_url":"https://github.com/MilanRgm","followers_url":"https://api.github.com/users/MilanRgm/followers","following_url":"https://api.github.com/users/MilanRgm/following{/other_user}","gists_url":"https://api.github.com/users/MilanRgm/gists{/gist_id}","starred_url":"https://api.github.com/users/MilanRgm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MilanRgm/subscriptions","organizations_url":"https://api.github.com/users/MilanRgm/orgs","repos_url":"https://api.github.com/users/MilanRgm/repos","events_url":"https://api.github.com/users/MilanRgm/events{/privacy}","received_events_url":"https://api.github.com/users/MilanRgm/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T14:21:21Z","updated_at":"2018-10-17T14:21:21Z","author_association":"NONE","body":"Thanks a lot for such quick reply. By custom mutate you mean to say something like this.\r\n\r\n```python\r\nclass ProfileUpdate(BaseMutation):\r\n    class Arguments:\r\n        input = ProfileInput(description='Fields required to update profile', required=True)\r\n\r\n    class Meta:\r\n        description = 'Updates Profile'\r\n        model = models.Profile\r\n\r\n    @classmethod\r\n    def mutate(cls, root, info, input):  \r\n        if info.context.user.is_authenticated:\r\n            profile = Profile.objects.get(user=info.context.user)\r\n            profile.name = input.get('name', None)\r\n            profile.email = input.get('email', None)\r\n            profile.phone_number = input.get('phone_number', None)\r\n            profile.save()\r\n            return ProfileUpdate(profile=profile)\r\n```"}}
{"actor":{"display_login":"MilanRgm"}}