Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
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,
});
/*
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.
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 ?
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.
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.
All the sessions of the conference are now available online