accounts
accounts copied to clipboard
Typeorm/Graphql: How to retrieve profile information (eg firstname/lastname) and where to store it
If using the createUser function on the frontend in order to create a user and when having included a profile (like in the official example), I'm wondering where this information is saved on the backend? Or if it's not saved, how I can retrieve it and save it manually? I'm using postgres and don't see the information stored in any of the tables.
Frontend code:
public onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
this.setState({ error: null });
try {
await accountsPassword.createUser({
email: this.state.email,
username: this.state.email,
password: this.state.password,
profile: {
firstName: this.state.firstName,
lastName: this.state.lastName,
},
})
this.props.history.push('/login/');
} catch (err) {
console.log(err)
this.setState({ error: err.message })
}
}
Backend (typeDefs):
extend input CreateUserInput {
profile: CreateUserProfileInput!
}
input CreateUserProfileInput {
firstName: String!
lastName: String!
}
Hi, I'm facing the same confusion. Any guidance available on this?
Where it's stored depended on the database adapter. All the existing database adapters store the additional fields together with the user. Check 1.0 examples, we don't have profile anymore but we simply extend CreateUserInput
with firstName and lastName.
Anyway the problem with the typeorm adapter is that it has standard entities which you cannot extend and in order to add additional fileds it does the following:
Object.assign(user, otherFields);
await this.userRepository.save(user);
How that works is black magic to me, but I admit I don't user typeorm since a long time.
The new MikroORM database adapter is much better in that regard because it allows you to extend the base entities any way you want. I don't plan to improve the typeorm adapter because typeorm's pace of development has basically stalled and mikro-orm is much better in my opinion nowadays.
Apparently it might be possible to extend the User entity, but that's not the approach that they've taken in the example. Feel free to try it.
How that works is black magic to me, but I admit I don't user typeorm since a long time.
Nevermind, apparently it doesn't work at all.