Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeorm/Graphql: How to retrieve profile information (eg firstname/lastname) and where to store it #768

Closed
derblitz opened this issue Aug 8, 2019 · 5 comments · Fixed by #1258

Comments

@derblitz
Copy link

derblitz commented Aug 8, 2019

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!
}
@stevenmasci
Copy link

Hi, I'm facing the same confusion. Any guidance available on this?

@darkbasic darkbasic added the 1.0 label Nov 22, 2023
@darkbasic
Copy link
Member

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.

@darkbasic
Copy link
Member

darkbasic commented Nov 22, 2023

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.

@darkbasic
Copy link
Member

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.

@darkbasic
Copy link
Member

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.

@darkbasic darkbasic added this to the 1.0 milestone Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants