cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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,
});
/*
4 REPLIES 4

MuddyBootsCode
Graph Steward

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 ?

MuddyBootsCode
Graph Steward

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.