I'm following this tutorial by Robin Wieruch
While implementing User Sign Up using jwt with GraphQL, I'm not able to provide the values through GraphQL Mutation
Server.js
const server = new ApolloServer({
typeDefs: gql(typeDefs),
resolvers,
context: { db },
secret: process.env.SECRET,
});
models/user.js
export default (sequelize, DataTypes) => {
const User = sequelize.define('user', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
username: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notempty: true,
len: [8],
},
},
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
validate:{
isEmail: true,
},
},
createdAt: {
},
createdAt: {
type: DataTypes.DATE,
allowNull: true
},
updatedAt: {
type: DataTypes.DATE,
allowNull: true
},
deleted_at: {
type: DataTypes.DATE,
allowNull: true
}
},
{
freezeTableName: true,
});
User.beforeCreate( async user => {
user.password = await user.generatePasswordHash();
});
User.prototype.generatePasswordHash = async function() {
const saltRounds = 10;
return await bcrypt.hash(this.password, saltRounds);
};
return User;
};
schema
type Mutation {
signUp(username: String!, email: String!, password: String!): Token!
}
type Token {
token: String!
}
resolvers
signUp: async(
parent,
{ username, password, email},
{db, secret },) => {
const user = await db.user.create({
username,
password,
email,
});
return { token: createToken(user, secret, '30m')};
},
I'm currently stuck with below GraphiQL Mutation:
mutation($username: String!, $password: String!, $email: String!){
signUp(username: $username, password: $password, email: $email){
u
}
}
As you can see, when I type, u, I should be seeing username, password and email getting auto-populated. Or may be my mutation format is not correct.
Please correct, where I'm wrong.
signUp(.....): Token!
- you should seetoken
– xadm