node.js – Variable of required type was not provided at graphql
I’m trying to send a query with qraphql. I’m trying to get userId as variable from arguments at resolver, but I have en error “Variable “$userId” of required type “UUID!” was not provided.”
const Query = new GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: userType,
description: 'Get user by Id',
args: {
id: {
type: UUIDType,
},
},
resolve: async (_, args: { userId: string }, _context) => {
try {
const user = await prisma.user.findUnique({
where: {
id: args.userId,
},
});
return user;
} catch {
return null;
}
},
}
})
userType is:
export const userType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: { type: new GraphQLNonNull(UUIDType) },
name: { type: new GraphQLNonNull(GraphQLString) },
balance: { type: new GraphQLNonNull(GraphQLFloat) },
})
});
The query is:
query ($userId: UUID!) {
user(id: $userId) {
id
name
balance
}
}
Why do I have this error?
I tried to find any information, but useless
Read more here: Source link
