Description
Problem
@vsuaste identified the following flaw in the current design.
For example, if we have two servers interconnected and from server A I fetch all records, then it will connect to server B to try to fetch all its records, but from B it will also try to connect to A to fetch all its records, and so on, in a infinite loop.
Solution
To avoid infinite loops add a property to searchInput GraphQL schema:
// extend the search input
input searchBookInput {
# ...
excludeAdapterNames: [String]
}
Note that we need to have a separate schema generator for distributed data models.
Resolver-Layer
For the resolver-layer implement a new helper that is able to parse the above search input and removes from the authorizedAdapters
those in the search input, if and only if the respective search input is defined, of course. Note that you add to the excludeAdapterNames
and not overwrite it. It may be sent from another server and already be excluding some adapters.
Data-Model-Layer
In the implementation of readAllCursor
consider the new argument authorizedAdapters
.
Now, when invoking the adapters inside the DDM's readAllCursor
do the following:
// personDDM.js
readAllCursor(search, pagination, sort, authorizedAdapters) {
// do the magic
let personPromises = authorizedAdapters.map( personAdapt => {
// basically exclude all _known_ adapters but the current "personAdapt"
// so the remote server referenced by current "personAdapt" does only query
// - its local adapters (e.g. SQL)
// - remote adapters, this server (HERE) server does know nothing about
let extendedSearchArg = search.excludeAdapterNames.push(
registeredAdapters.remove( personAdapt.name() )
)
return personAdapt.readAllCursor( extendedSearchArg, ... )
} )
let allResults = Promise.all( personPromises )
// continue as before
Documentation
Add to the documentation (manual) and make very clear:
- In all connected servers the adapter-names referring to the same server need to be identical.
- In all connected server the adapter-names must be unique. No two adapters that point to different servers but have the same name are permitted. This causes infinite loops!