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

Update using POST instead of PATCH #58

Closed
hoIIer opened this issue May 13, 2022 · 2 comments
Closed

Update using POST instead of PATCH #58

hoIIer opened this issue May 13, 2022 · 2 comments

Comments

@hoIIer
Copy link

hoIIer commented May 13, 2022

I have an item previously returned by the api in the form:

  {
    id: 1,
    fieldA: 'abc',
  }

where the schema is defined as:

    schema: {
      widgets: {
        type: 'widgets',
        fields: {
          fieldA: {
            type: 'string',
            readOnly: true,
          },
          fieldB: 'string',
        }
      }
    }

I want to do a PATCH request which according to the docs Defaults to POST when creating a resource, and PATCH when updating.

I am doing the following which is resulting in a POST instead of a PATCH.

  const [patchWidget] = useMutation('widgets');

  const submit = async (widget) => {
    widget.fieldB = new Date();

    await patchWidget(widget));
  }

What is the proper way to create a PATCH request without specifying it as an option in the mutation?

e.g. PATCH /api/widgets/1

edit

I was able to get it working with

    const res = await client.mutate(['widgets', widget.id], {
      fieldB: new Date(),
    });

But will leave open because wondering if I need to use the client directly to get PATCH behavior

@aribouius
Copy link
Owner

@Holler the useMutation hook works the same as the client. This should work:

const [patchWidget] = useMutation(['widgets', widget.id]);

@hoIIer
Copy link
Author

hoIIer commented May 29, 2022

@aribouius ah I see, thanks!

@hoIIer hoIIer closed this as completed May 29, 2022
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

No branches or pull requests

2 participants