Open ian opened 4 years ago
I have the same issue. Custom resolvers in neo4j-graphql-js have very limited use.
I agree, greater flexibility with custom mutations is needed. This issue I raised is somewhat related: 505.
Ultimately we agree it would be great to have low level functionality which can generate cypher components - node update params and selections for use in custom cypher statements would be a good starting point
Since I have updated issue #505, I thought I would check in here with a potential solution for you @ian.
Whilst this requires writing and running your own cypher statement, I think you can achieve what you need to. Your code could include something like this:
const CreateThing = async (object, params, ctx, resolveInfo) => {
const { driver } = ctx;
const session = driver.session();
const selectionCypher = generateSelectionCypher(ctx, resolveInfo); // see #505
Object.assign(params, {
slug: slug(params.name),
user: ctx.user.id,
});
const statement = `
CREATE (thing:Thing $params)
RETURN ${selectionCypher}
`;
const respData = await session
.run(statement, params)
.then((res) => {
console.log(res);
return res;
})
.then((res) => res.records[0].get("thing"));
await session.close();
return respData;
}
It seems that the params passed to the
neo4jgraphql
call are hard locked to only the params that are specified the schema mutation.What is the preferred way to add additional create params in an overridden mutation?
Consider this example: