Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Add initial support for bookmarks #460

Merged
merged 1 commit into from
Jul 2, 2020
Merged

Add initial support for bookmarks #460

merged 1 commit into from
Jul 2, 2020

Conversation

johnymontana
Copy link
Contributor

@johnymontana johnymontana commented Jun 23, 2020

Check the context object for a neo4jBookmarks value and pass
along during session creation if the value exists.

For example, to set the context.neo4jBookmarks value from a request header (in this case headers.neo4jbookmarks) using Apollo Server:

const server = new ApolloServer({
  schema,
  context: ({ req }) => {
    return {
      driver,
      neo4jBookmarks: req.headers['neo4jbookmark']
    };
  }
});

Screen Shot 2020-06-23 at 11 17 22 AM

Check the context object for a neo4jBookmarks value and pass
along during session creation is the value exists.
@johnymontana
Copy link
Contributor Author

Note that the way this is implemented will only work for v4.x versions of neo4j-javascript-driver

context: ({ req }) => {
return {
driver,
neo4jBookmarks: req.headers['neo4jbookmark']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnymontana is there some related documentation we can follow?
Sorry for my lack of Neo4j experience, so far I thought bookmarks were only used by read replica to stay up to date with the core servers in the context of the raft protocol.

Reading up on Causal chaining and bookmarks, it seems like the driver's session has a lastBookmark() method available.
But I do not see a context.neo4jBookmarks = context.driver.session().lastBookmark() initialization in your code.
Do I need to manually set req.headers['neo4jbookmark'] = context.driver.session().lastBookmark() then?

It seems like the example provided by the doc shows how to ensure that person nodes have been created before attempting to create a friendship relationship. It's difficult to imagine a similar real-life use case (a server would need to have access to both node information in order for a client to attempt a friendship connection with another).
What would be a practical use-case here? I initially thought about cursors and connections, but I suppose bookmarks are unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case here is to support situations where a service other than neo4j-graphql.js is writing to the Neo4j cluster and we want the queries generated by neo4j-graphql.js to maintain the causal chain and only execute as of the last transaction to the cluster from that external service, as indicated by passing the bookmark returned from the external service's write transaction.

So you're correct in pointing out that this is only partial support for bookmarks in neo4j-graphql.js. What is missing is the ability to return a bookmark from a transaction executed via neo4j-graphql.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense now, thanks!

@johnymontana johnymontana merged commit 136d794 into master Jul 2, 2020
@johnymontana johnymontana added the Needs docs Document the features added in this PR better label Oct 15, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Needs docs Document the features added in this PR better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants