-
Notifications
You must be signed in to change notification settings - Fork 15
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
Custom User fields work in currentUser query but not login mutation #41
Comments
The problem is indeed @SpaceK33z Do you want a PR for this? Without this functionality, a 2nd query is always required on login to get the actual desired findUserByEmail(ctx: object, email: string, info?: any) {
// Build query AST of fields required/expected by this package
const query = gql`
{
id
email
password
name
inviteToken
inviteAccepted
emailConfirmed
emailConfirmToken
resetToken
resetExpires
deletedAt
lastLogin
joinedAt
}
`;
// Check if application requested any additional fields of the User object
// If so, merge them in with the selections required above
if(info){
const requiredSelections = query.definitions[0].selectionSet.selections;
const topLevelSelections = info.operation.selectionSet.selections[0].selectionSet.selections;
const userSelections = topLevelSelections.find(s => s.name.value === 'user');
if(userSelections){
query.definitions[0].selectionSet.selections = [...requiredSelections, ...userSelections.selectionSet.selections];
}
}
return this.db(ctx).query.user({ where: { email } }, query);
} |
Update to support any fragments passed to findUserByEmail(ctx: object, email: string, info?: any) {
// Build query AST of fields required/expected by this package
const query = gql`
{
id
email
password
name
inviteToken
inviteAccepted
emailConfirmed
emailConfirmToken
resetToken
resetExpires
deletedAt
lastLogin
joinedAt
}
`;
// Check if application requested any additional fields of the User object
// or supplied any fragments.
// If so, merge them in with the required above
if(info){
const requiredSelections = query.definitions[0].selectionSet.selections;
const topLevelSelections = info.operation.selectionSet.selections[0].selectionSet.selections;
const userSelections = topLevelSelections.find(s => s.name.value === 'user');
if(userSelections){
query.definitions[0].selectionSet.selections = [...requiredSelections, ...userSelections.selectionSet.selections];
}
if(info.fragments){
for(const fragmentName in info.fragments){
const fragment = info.fragments[fragmentName];
query.definitions.push(fragment);
}
}
}
return this.db(ctx).query.user({ where: { email } }, query);
} |
I've added the field
roles
to myUser
type:and it works great when calling the
currentUser
query:but even though it's a required field, it returns
null
with theAuthPayload
oflogin
mutation:Any thoughts on why this is? Both the return types of
currentUser
andlogin
reference the sameUser
type. The resolvers for each handles them a bit differently.currentUser
:findUserById(ctx, id, info)
login
:findUserByEmail(ctx, email)
info
is an optional arg tofindUserByEmail
and it's not passed. Is this why it does not include other fields on the returneduser
? I'm having trouble following the flow...Thanks!
The text was updated successfully, but these errors were encountered: