cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Resolve with an array return duplicates

apollo-server-lambda & neo4j-driver

I'm doing a query where I find out the users that someone is following. The console.log of 'collectedNames' in the backend shows the array of 4 users that they are following and all the correct properties. Somehow with the resolve I end up on the frontend with a repeat list of the same user 4 times. Any thoughts on why that could be and/or how I could improve this type of query

ListUsersFollowing: (root, args, context) => {
      return new Promise((resolve, reject) => {
        let session = driver.session();
        let params = { cognitoId: args.cognitoId };
        let query = `
                MATCH (currentUser:User { cognitoId: $cognitoId }) - [:FOLLOWING] -> (users:User)
                RETURN users
                ;`;

        return (
          session
            .run(query, params)
            .then(function(result) {
              if (result.records.length < 1) {
                return resolve(null);
              }
              let collectedNames = []; // How you return/resolve with an array
              result.records.map(record => {
                console.log(
                  "properties of the record",
                  record,
                  record.get("users").properties
                );
                let user = record.get("users").properties;
                collectedNames.push(user);
              });
              console.log(
                "collected names LIST USERS FOLLOWING",
                collectedNames
              );
              return resolve(collectedNames); 
            })
            .catch(error => {
              reject(error);
            })
        );
      });
    }
1 REPLY 1

MuddyBootsCode
Graph Steward

Did you get this figured out? What exactly is being returned from the query? It might be necessary to map through the return object to get all of the returned users.