vulcan-npm
vulcan-npm copied to clipboard
Updating user form fields in Smart Form
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:
- Create a SmartForm for updating user profile fields based on
meteor-demo.tsx
, usinguseUpdate({model: User})
. - 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
I suspect this is an issue in the default fragment generator @Timi-Duban , from package @vulcanjs/graphql
Another small issue: when document is not found, the hook will still try to update the lists using multiQueryUpdater => it should not