Simple registration resolvers
![personablach personablach](https://community.neo4j.com/legacyfs/online/2X/4/466a43199849a775fd53eaafa8639ed470692b9e.png)
‎04-25-2020 12:54 PM
I've been struggling for a minute trying to write a custom resolver for checking if a user exists by email and logically creating or logging in a user.
Im really shocked I can't find one functional example of this based on GRAND
I can understand if I'm missing the point entirely and need to separate these concerns into separate queries/mutations but then I'm not really sure what the flow is. Any examples or obvious uses? Is there an example of server side utility queries? can I import autogenerated resolvers here?
const resolvers = {
Mutation: {
Register: async (_, { email, password }) => {
const hashedPassword = await bcrypt.hash(password, 10);
const emailExists = await /** SOME WAY TO FETCH
BOOLEAN FROM-Query ---> */ userByEmail({ email });
if(!emailExists)
return /** SOME WAY TO
TRIGGER MUTATION ---> */ createUser({
variables: {
email: email,
uid: hashedPassword,
},
});
},
Login: async (_, { email, password }, { res }) => {
const user = await /** ALL THE EXAMPLES I SEE ARE
FOR SETUPS WITH ANYTHING BUT NEO4J/APOLLO
CACHE AS DATASTORE ----> */ User.findOne({ where: { email } });
if (!user) {
return null;
}
const valid = await bcrypt.compare(password, user.password);
if (!valid) {
return null;
}
const r = sign({ userId: user.id, count: user.count }, process.env.R, {
expiresIn: '7d',
});
const a = sign({ userId: user.id }, process.env.A, {
expiresIn: '15min',
});
res.cookie('r', r);
res.cookie('a', a);
return user;
},
},
};
const schema = makeAugmentedSchema({
typeDefs,
resolvers,
});
/*
- Labels:
-
GraphQL-and-GRANDstack
![MuddyBootsCode MuddyBootsCode](https://community.neo4j.com/legacyfs/online/2X/7/7b1e57bcf619a1531fb53f6cc4e0cb83c5c27f06.jpeg)
‎04-28-2020 09:54 AM
The GRANDstack and it's drivers auto create your resolvers for you. So you don't need to do that unless you want a lot of custom behavior or need something different. In which case there are ways to exclude the auto generated resovlers completely.
![nguita_erik nguita_erik](https://community.neo4j.com/legacyfs/online/2X/d/d3a6329398d8f60692b40bbe9102ac6bebc60f86.jpeg)
‎01-22-2021 09:21 AM
Yes, GRANDSTACK create resolvers. But it doesn't create registration resolvers.
How can i implement registration workflow in GRANDSTACK ?
![MuddyBootsCode MuddyBootsCode](https://community.neo4j.com/legacyfs/online/2X/7/7b1e57bcf619a1531fb53f6cc4e0cb83c5c27f06.jpeg)
‎01-22-2021 09:55 AM
https://grandstack.io/docs/graphql-schema-generation-augmentation Should be able to create them as custom resolvers and add them.
![nguita_erik nguita_erik](https://community.neo4j.com/legacyfs/online/2X/d/d3a6329398d8f60692b40bbe9102ac6bebc60f86.jpeg)
‎01-22-2021 10:09 AM
There are CRUD operations, but not the registration workflow.
I found a nice repo with detailed example.
maybe it will be useful, and can be used in further documentation examples.
![](/skins/images/DCEE200A061243D9CDD43EC39D921EED/responsive_peak/images/icon_anonymous_message.png)