export const userTypeDefs = `
type User {
id: ID!
email: String!
password: String!
firstName: String!
lastName: String
# We have 2 new fields, "workspaceId" and "workspace"
# The workspaceId will be the id of the item and workspace
# will be the actual populated workspace object
workspaceId: String
workspace: Workspace
}
// code...
`;
export const userResolvers = {
Query: {
// Query resolvers...
},
Mutation: {
// Mutation resolvers...
},
User: {
async workspace(user: { workspaceId: string }) {
if (user.workspaceId) {
const workspace: any = await Workspace.findById(user.workspaceId);
return workspace.toGraph();
}
return null;
},
},
};