VulcanJS / vulcan-npm

The full-stack JavaScript App Framework
https://vulcan-docs.vercel.app
MIT License
31 stars 8 forks source link

Updating user form fields in Smart Form #59

Open GraemeFulton opened 3 years ago

GraemeFulton commented 3 years ago

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
eric-burel commented 3 years ago

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

eric-burel commented 3 years ago

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