Skip to content

Types missing for custom resolver #489

Closed
@kimroen

Description

@kimroen

As documented here and added to this library here, when creating a driver you can pass in a custom resolver:

import neo4j from 'neo4j-driver';

const driver = neo4j.driver(
  'my-uri',
  neo4j.auth.basic('username', 'password'),
  {
    resolver: address => ['my', 'array', 'of', 'addresses'],
  },
);

With the current types, this doesn't work. You are told that resolver isn't a known property on Config.

This seems fair enough, because we can see that this is the case in the type definition here:

declare interface Config {
encrypted?: boolean | EncryptionLevel
trust?: TrustStrategy
trustedCertificates?: string[]
knownHosts?: string
/**
* @deprecated use {@link maxConnectionPoolSize} instead.
*/
connectionPoolSize?: number
maxConnectionPoolSize?: number
maxTransactionRetryTime?: number
loadBalancingStrategy?: LoadBalancingStrategy
maxConnectionLifetime?: number
connectionTimeout?: number
disableLosslessIntegers?: boolean
logging?: LoggingConfig
}

This resolver function isn't used immediately anywhere, it happens quite far away from the constructor. I'm guessing that the resolver referenced here is the one we're looking for:

resolve (seedRouter) {
return new Promise(resolve =>
resolve(this._resolverFunction(seedRouter.asHostPort()))
).then(resolved => {
if (!Array.isArray(resolved)) {
throw new TypeError(
`Configured resolver function should either return an array of addresses or a Promise resolved with an array of addresses.` +
`Each address is '<host>:<port>'. Got: ${resolved}`
)
}
return resolved.map(r => ServerAddress.fromUrl(r))
})

If so, the definition should be something like this, allowing either an array of strings or a promise resolving to an array of strings:

declare interface Config {
  ...
  resolver?: (address: string) => Promise<string[]> | string[]
}

Hope that's useful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions