# @theorchard/connector-neo4j

Common logic for getting neo4j driver.

## Usage

### Basic usage

Before you create a new ApolloServer you can create the drivers. This way you can use the same driver connection for all requests.

```
const { serviceName } = config;
const featuresConfig = {
    splitApiKey: 'key',
    featuresInUse: ['neo4j_aura'],
    debug
};

initSplitClient(featuresConfig);
initNeo4jDriver(serviceName);

```

Optionally you can pass neo4j config variables (<code>connectionAcquisitionTimeout</code>, <code>connectionLivenessCheckTimeout</code>, <code>connectionTimeout</code>, <code>maxConnectionLifetime</code>, <code>maxConnectionPoolSize</code>, and/or <code>maxTransactionRetryTime</code>)

```
const options = {
    connectionAcquisitionTimeout: 30000
    connectionTimeout: 60000,
    maxConnectionPoolSize: 100
};

initSplitClient(featuresConfig, options);

```

In context were you want to return the driver instance you can call

```
context: async ({ req }) => {

    ...

    const requestHeaders = {
        profileType,
        profileId,
        identityId,
        correlationId,
        driver: getNeo4jDriver()
    };
    return requestHeaders;
}

```

## Dependencies

1. It reads the credentials from env vars. QA and Prod graphql will have these env vars from secrets manager bound in Terraform module.

Eg: https://github.com/theorchard/terraform-infra/blob/master/qa/graphql-knowledge/main.tf#L149-L152

```
NEO4J_URL='neo4j+s://dev-neo4j-cluster.dev.theorchard.io:7687'
NEO4J_USER=
NEO4J_PASSWORD=
NEO4J_AURA_URL=
NEO4J_AURA_USERNAME=
NEO4J_AURA_PASSWORD=
```

2. It assumes that the split client in connector-splitio has already been initilized using `initSplitClient`.
