I am experiencing a problem. I searched and tried everything. It is about a networking issue I think or a bug in GraphQL(Apollo-Server-Express). I am sending a query that seems to be perfectly correct and fine, tested the values and they are all good. I send the request and it shows a 200 status code, it shows the content to be correct. However, the problem arises when I open the networking window in the dev tools. It gives me an error that the value expected is a String but it received undefined. Even when it's clearly visible even in the request payload. I did check the schema and it seems correct. Now I have no idea why it does that. Actually, I receive the data inside the resolver but all of it is in a single variable(password) as an object while the other variable(email) is undefined. I have no middleware that can hurt incoming requests.
Client-side query:
signIn: (email: string, password: string) => requests.post({query: `
query ($email: String!, $password: String!) {
signIn(email: $email, password: $password) {
_id
name
email
avatar
admin
rents{
_id
}
createdAt
updatedAt
}
}
`, variables: {
email: email,
password: password,
}}),
Your signIn
function is broken. It does not receive email
and password
as the first two arguments, as your method has declared them. Like every resolver function, the first parameter is the parent object (the root object in case of Query
fields) and the second parameter is an object of arguments.
The output of the log statements in your server code should have made this obvious.
To fix your code, use
const Query = {
async signIn(_root, args, _context) {
// ^^^^
const { email, password } = args;
…
}
};
or
const Query = {
async signIn(_root, {email, password}, _context) {
// ^^^^^^^^^^^^^^^^^
…
}
};