Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types missing for custom resolver #489

Closed
kimroen opened this issue Sep 27, 2019 · 1 comment
Closed

Types missing for custom resolver #489

kimroen opened this issue Sep 27, 2019 · 1 comment

Comments

@kimroen
Copy link

kimroen commented Sep 27, 2019

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!

@zhenlineo
Copy link
Contributor

Thanks very much for reporting this. We will plan a release to includes the fixes soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants