I am currently trying to use GraphQL with NodeJS, and I do not know why this error occurs with the following query:
{
library{
name,
user {
name
email
}
}
}
I'm not sure type
of my resolveLibrary
rights, because in any instance I saw that they used new GraphQL.GraphQLList()
, but in my case I really want to return a user object, not an array of users.
My code is:
const GraphQL = require('graphql');
const DB = require('../database/db');
const user = require('./user').type;
const library = new GraphQL.GraphQLObjectType({
name: 'library',
description: `This represents a user library`,
fields: () => {
return {
name: {
type: GraphQL.GraphQLString,
resolve(library) {
return library.name;
}
},
user: {
type: user,
resolve(library) {
console.log(library.user);
return library.user
}
}
}
}
});
const resolveLibrary = {
type: library,
resolve(root) {
return {
name: 'My fancy library',
user: {
name: 'User name',
email: {
email: 'test@123.de'
}
}
}
}
}
module.exports = resolveLibrary;
Error:
Error: Expected Iterable, but did not find one for field library.user.
So, my schema library
provides a field user
that returns the correct data (the .log console is called).
source
share