I have been losing all Saturday trying to figure out this. I am good in frontend and decided to jump in and learn back end as well. I have been very interested in graphQl and since I was already doing a lot with firebase it was a go. I decided to learn the graphQl server but cannot figure out what I am doing wrong.
I have this resolver to create a firebase account:
module.exports = {
Mutation: {
registerUser: async (
_,
{ registerInput: { username, email, password } },
context,
info
) => {
const register = await admin
.auth()
.createUser({
email,
emailVerified: false,
password: password,
displayName: username,
disabled: false
})
.then(function(userRecord) {
console.log("Successfully created new user:", userRecord.uid);
const {userData} = admin
.firestore()
.collection("users")
.doc(userRecord.uid)
.set(
{
email,
role: "user",
username,
uid: userRecord.uid
}, {merge: true});
return register
})
.catch(function(error) {
console.log("Error creating new user:", error);
});
return register
}
and in the schema:
type Mutation {
registerUser(registerInput: RegisterInput): User!
type User {
firstName: String
lastName: String
password: String!
adress: String
postCode: String
role: String
ort: String
email: String!
phone: String
responseRate: Float
responseTime: Int
profilePicture: String
token: String
username: String!
personnummer: Int
}
input RegisterInput{
username: String!
email: String!
password: String!
}
However when I run it in the playground, sometimes the account and the document about the user gets created, other times doesn't, but I always get the same error on the playground:
"errors": [
{
"message": "Cannot return null for non-nullable field Mutation.registerUser.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"registerUser"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Cannot return null for non-nullable field Mutation.registerUser.",
" at completeValue