# datasource-neo4j

A datasource for interacting with Neo4j.

## Usage

### Basic Setup

```typescript
import Neo4jDataSource from '@theorchard/datasource-neo4j';
import { getNeo4jDriver } from '@theorchard/connector-neo4j';

const context = {
    driver: getNeo4jDriver(),
    database: 'graph.db', // Optional

const dataSource = new Neo4jDataSource(context);
```

### Apollo Server Setup

```typescript
import { startApolloServer } from '@theorchard/graphql-server';
import { getNeo4jDriver } from '@theorchard/connector-neo4j';
import Neo4jDataSource from '@theorchard/datasource-neo4j';

const startServer = async (config) => {
    await startApolloServer({
        config,
        resolvers,
        createDataSources: () => ({
            neo4j: new Neo4jDataSource({
                // Set props on Datasource Creation
                driver: getNeo4jDriver(),
                database: 'graph.db',
            }),
        }),
        createContext: (ctx) => {
            // or set on Apollo context
            return {
                ...ctx,
                driver: getNeo4jDriver(),
                database: 'graph.db',
            };
        },
        // ...
    });
};
```

## Notes

-   The `database` property is optional. If omitted, the default Neo4j database is used.
-   All session and transaction helpers automatically use the configured database if provided.
-   If a `bookmarkManager` is provided in the context object, this will be passed through to the created neo4j session.
