GraphQL Expected Iterable, but could not find it for field xxx.yyy

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 typeof my resolveLibraryrights, 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 libraryprovides a field userthat returns the correct data (the .log console is called).

+5
source share
3 answers

, , . , , , .

, Expected Iterable, but did not find one for field library.user. (Iterable), resolver

schema.js:

login(email: String, password: String): [SuccessfulLogin]

:

login(email: String, password: String): SuccessfulLogin

"SuccessfulLogin". , resolver .

+4

, user GraphQLList, .

+3

. find .

0
source

Source: https://habr.com/ru/post/1686720/


All Articles