Simple registration resolvers

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,
});
/*
1 Like

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.

Yes, GRANDSTACK create resolvers. But it doesn't create registration resolvers.

How can i implement registration workflow in GRANDSTACK ?

https://grandstack.io/docs/graphql-schema-generation-augmentation Should be able to create them as custom resolvers and add them.

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.