mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
new behaviour: single resolver returns null if documentId is not defined
This commit is contained in:
parent
4dda9919fe
commit
10603d000f
2 changed files with 6 additions and 2 deletions
|
@ -49,7 +49,6 @@
|
|||
"intl": "^1.2.4",
|
||||
"intl-locales-supported": "^1.0.0",
|
||||
"juice": "^1.11.0",
|
||||
"later": "^1.2.0",
|
||||
"lodash": "^4.17.10",
|
||||
"mailchimp": "^1.1.6",
|
||||
"marked": "^0.3.9",
|
||||
|
|
|
@ -110,12 +110,17 @@ export function getDefaultResolvers(options) {
|
|||
|
||||
// use Dataloader if doc is selected by documentId/_id
|
||||
const documentId = selector.documentId || selector._id;
|
||||
const doc = documentId ? await collection.loader.load(documentId) : await Connectors.get(collection, selector);
|
||||
// documentId can be undefined, this is NOT a failure case
|
||||
// for example it allows form to have a "edit" and "new" mode withtout
|
||||
// needing to swap the withSingle hoc
|
||||
if (!documentId) return { result: null };
|
||||
|
||||
const doc = await collection.loader.load(documentId);
|
||||
if (!doc) {
|
||||
if (allowNull) {
|
||||
return { result: null };
|
||||
} else {
|
||||
// if documentId is provided but no document is found, this is usually a failure case
|
||||
const MissingDocumentError = createError('app.missing_document', { message: 'app.missing_document' });
|
||||
throw new MissingDocumentError({ data: { documentId, selector } });
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue