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

I suspect this is an issue in the default fragment generator @Timi-Duban , from package @vulcanjs/graphql

eric-burel avatar Jul 01 '21 20:07 eric-burel

Another small issue: when document is not found, the hook will still try to update the lists using multiQueryUpdater => it should not

eric-burel avatar Jul 06 '21 06:07 eric-burel