Skip to content

Instantly share code, notes, and snippets.

@acomito
Last active August 11, 2019 12:50
Show Gist options
  • Save acomito/5daa36bdb2a4d67daf7ebd8d4497e9e8 to your computer and use it in GitHub Desktop.
Save acomito/5daa36bdb2a4d67daf7ebd8d4497e9e8 to your computer and use it in GitHub Desktop.
import { gql } from 'apollo-server';
import UserProfiles from 'collections/UserProfiles/model';
import Users from 'collections/Users/helpers';
export const UserProfileResolvers = {
UserProfile: {
id: root => {
// in some cases we'll already have masked _id for id, so check if id exists and return that if it does exist
if (root.id) return root.id;
// if id doesn't exist yet, we'll return _id as id
if (root._id) return root._id;
},
email: async root => {
let id;
// in some cases we'll already have masked _id for id, so check if id exists and return that if it does exist
if (root.id) id = root.id;
// if id doesn't exist yet, we'll return _id as id
if (root._id) id = root._id;
let user = await Users.getById(id);
console.log(user.emails);
return user.emails[0].address;
}
}
};
export const UserProfileSchema = gql`
"The main User object used for authentication etc"
type UserProfile {
id: String
firstName: String
lastName: String
email: String
emails: [EmailRecord]
}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment