Instructor: Our scraper is currently executing mutations using the add relationship mutations provided by neo4j-graphql-js. Because these use the create clause under the hood, applying the same mutation multiple times will result in identical nodes or relationships being created.
The Cypher directive can help us solve this problem by allowing us to define custom Cypher queries in our mutations. For instance, ones using the merge clause. We can add some mutations to our schema for node creation using this Cypher directive.
If we were interested in doing a little more work, we could define a more robust input type and create a more complex Cypher statement. Let's keep our implementation as simple as possible for now though.
We can run the node creation section of the scraper we used before and still expect to have only one instance of each node. The relationship mutations can be overridden in the same way, unlike the generated relationship mutations. We'll just return the from part of each relationship to keep our Cypher statement simple.
Because the output data type is changing, we'll need to update the scraper script to return the correct properties. We can run our scraper as many times as we'd like and still have an intact and coherent graph after every run.