cancel
Showing results for 
Search instead for 
Did you mean: 

Passing unwind parameter issue

Hi, I am trying to pass a graph ql arguments array in cypher query. I am having difficulty making query work. I can see the parameter passed correctly while doing a console log. However, when I try to utilize it with node js. Neo4j driver is not doing anything. I think, I am doing something wrong. Could anyone please guide me.

const query = `UNWIND $list as batch
match ((u:user { ohrid: ${ctx.ohrid}})-[:FILE_SHARED_WITH| FILE_SHARED_WITH_GROUP| MEMBER_OF_GROUP*..2]-(f:file)) where f.uuid = batch.uuid
SET f.documentStatus = batch.documentStatus
return f as files`;
 
const queryParams = { list: args.documents };
const result = await session.run(query, queryParams);

if i use the same query in neo4j browser it works fine

UNWIND [{uuid: "5f668fbb-70b3-4713-bc91-18727fb5ac65", documentStatus: "unpublished"}, {uuid: "84e0575c-9c5c-43b5-a4fc-3af99bcf98ec", documentStatus: "unpublished"}] as batch
match ((u:user { ohrid: 850046714})-[:FILE_SHARED_WITH| FILE_SHARED_WITH_GROUP| MEMBER_OF_GROUP*..2]-(f:file)) where f.uuid = batch.uuid and any(x in batch.documentStatus where x in ['published', 'unpublished'])
SET f.documentStatus = batch.documentStatus
return f

Cheers
~ Meet

5 REPLIES 5

niclasko
Node Clone

In your second query you refer to batch.id, but in your first query you refer to batch.uuid (which might not exist?)

Could that be the issue?

my apologies, I have updated the query accordingly now. I was trying out something and pasted that query here. I have tried many ways none of them are working.

some docs says use {list}, others says $list. so far none working for me.

it has been resolved now.

I'm facing the same problem. Would you mind sharing your solution?

Cheers
Hannes

david_king2
Node Link

use query parms:

 const queryParams = {items: items, moduleName: moduleName, projectName: projectName};
        const query = `
            UNWIND $items AS item            
                WITH item
                MERGE (root: ROOT {code: $projectName})
                MERGE (module: MODULE {name: $moduleName})-[:HAS_MODULE]->(root)
                MERGE (component:Component {component: item.component})
                    ON CREATE SET 
                        component.componentName = item.componentName, 
                        component.componentVersion = item.componentVersion        
                MERGE (module)-[:HAS_COMPONENT {development: item.development, production: item.production}]->(component)     
            RETURN properties(component) AS props
        `;
        console.log(`Processing ${items.length} dependencies for module: ${moduleName}`);
        await driver.session().run(query, queryParams)
            .then(result => {
                result.records.forEach(record => {
                    results.push(record.get('props'));
                })
            })
            .catch(error => {
                console.log(error)
            })
            .then(() => {
                driver.session().close();
                console.log('OK!')
            });