vulcan-npm icon indicating copy to clipboard operation
vulcan-npm copied to clipboard

Updating user form fields in Smart Form

Open GraemeFulton opened this issue 3 years ago • 2 comments

Describe the bug Updating user form fields gives the following error: Cannot query field "userId" on type "User". Did you mean "username"?, Location: line 14, col 3, Path: undefined

To make it work, you have to manually add userId to your User schema.

The default fragment somehow systematically includes userId but User is an exception: it doesn't have an userId in its schema

To Reproduce Steps to reproduce the behavior:

  1. Create a SmartForm for updating user profile fields based on meteor-demo.tsx, using useUpdate({model: User}).
  2. When you press update, you get the above error

Expected behavior The form should successfully update user fields without any modification to the user schema


Here is my demo form that was not working:

import {
  useUpdate,
} from "@vulcanjs/react-hooks";
import { User } from "../../models/meteorUser";
const ProfileForm = (props) => {
    const [updateDocument] = useUpdate({ model: User });
    if(props.user){
      return (
        <form
          onSubmit={async (evt) => {
            evt.preventDefault();
            evt.stopPropagation();
            const displayName = (evt.target as any).displayName.value;
            // const url = (evt.target as any).url.value;
            await updateDocument({
              input: { id: props.user._id, data: { displayName } },
            });
          }}
        >
          <input
            placeholder="name"
            type="text"
            name="displayName"
            defaultValue={props.user.displayName}
          />
          <button type="submit">Update</button>
        </form>
      );
    }else{
      return null
    }
  };
  export default ProfileForm

GraemeFulton avatar Jun 30 '21 13:06 GraemeFulton