From e8472d5d1272a3203e34eaab7e2aa7a7cfe1efaf Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 13 May 2020 13:56:59 +0200 Subject: [PATCH] Change subscription attributes presence checks --- src/engine/subscription/Subscription.spec.ts | 3 +- src/engine/subscription/Subscription.ts | 40 +++++++++---------- .../__snapshots__/Subscription.spec.ts.snap | 2 + .../__snapshots__/generator.spec.ts.snap | 2 - 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/engine/subscription/Subscription.spec.ts b/src/engine/subscription/Subscription.spec.ts index caf9ded8..0bb10351 100644 --- a/src/engine/subscription/Subscription.spec.ts +++ b/src/engine/subscription/Subscription.spec.ts @@ -250,7 +250,8 @@ describe('Subscription', () => { expect(fn).toThrowErrorMatchingSnapshot(); }); - it('should throw if required attribute is missing in CREATE type subscriptions', () => { + // this check seems useless for subscription + it.skip('should throw if required attribute is missing in CREATE type subscriptions', () => { function fn() { const otherEntity = new Entity({ name: 'SomeEntityName', diff --git a/src/engine/subscription/Subscription.ts b/src/engine/subscription/Subscription.ts index 559fdc8d..d8670d3f 100644 --- a/src/engine/subscription/Subscription.ts +++ b/src/engine/subscription/Subscription.ts @@ -125,16 +125,17 @@ export class Subscription { if (this.type === SUBSCRIPTION_TYPE_CREATE) { this.isTypeCreate = true; + this.ignoreRequired = true; } if (this.type === SUBSCRIPTION_TYPE_UPDATE) { - this.needsInstance = true; + // this.needsInstance = true; this.ignoreRequired = true; this.isTypeUpdate = true; } if (this.type === SUBSCRIPTION_TYPE_DELETE) { - this.needsInstance = true; + // this.needsInstance = true; this.isTypeDelete = true; } @@ -241,24 +242,23 @@ export const processEntitySubscriptions = ( ); }); - if (subscription.type === SUBSCRIPTION_TYPE_CREATE) { - // todo : remove this check ? - const missingAttributeNames = requiredAttributeNames.filter( - requiredAttributeName => { - return !subscription.attributes.includes(requiredAttributeName); - }, - ); - - passOrThrow( - missingAttributeNames.length === 0, - () => - `Missing required attributes in subscription '${entity.name}.${ - subscription.name - }' need to have a defaultValue() function: [ ${missingAttributeNames.join( - ', ', - )} ]`, - ); - } + // if (subscription.type === SUBSCRIPTION_TYPE_CREATE) { + // const missingAttributeNames = requiredAttributeNames.filter( + // requiredAttributeName => { + // return !subscription.attributes.includes(requiredAttributeName); + // }, + // ); + + // passOrThrow( + // missingAttributeNames.length === 0, + // () => + // `Missing required attributes in subscription '${entity.name}.${ + // subscription.name + // }' need to have a defaultValue() function: [ ${missingAttributeNames.join( + // ', ', + // )} ]`, + // ); + // } } else if ( subscription.type === SUBSCRIPTION_TYPE_CREATE || subscription.type === SUBSCRIPTION_TYPE_UPDATE diff --git a/src/engine/subscription/__snapshots__/Subscription.spec.ts.snap b/src/engine/subscription/__snapshots__/Subscription.spec.ts.snap index 9df0e641..a06db802 100644 --- a/src/engine/subscription/__snapshots__/Subscription.spec.ts.snap +++ b/src/engine/subscription/__snapshots__/Subscription.spec.ts.snap @@ -9,6 +9,7 @@ Subscription { ], "delimiter": "/", "description": "build item", + "ignoreRequired": true, "isTypeCreate": true, "name": "SomeSubWithPostProcessor", "postProcessor": [Function], @@ -67,6 +68,7 @@ Subscription { ], "delimiter": "/", "description": "build item", + "ignoreRequired": true, "isTypeCreate": true, "name": "SomeSubWithPreProcessor", "preProcessor": [Function], diff --git a/src/graphqlProtocol/__snapshots__/generator.spec.ts.snap b/src/graphqlProtocol/__snapshots__/generator.spec.ts.snap index 351a0b03..f6fc20e1 100644 --- a/src/graphqlProtocol/__snapshots__/generator.spec.ts.snap +++ b/src/graphqlProtocol/__snapshots__/generator.spec.ts.snap @@ -38,10 +38,8 @@ GraphQLSchema { "OnCreateTestEntityNameInstanceNestedInput": "OnCreateTestEntityNameInstanceNestedInput", "OnCreateTestEntityNameNestedInput": "OnCreateTestEntityNameNestedInput", "OnCreateTestEntityNameOutput": "OnCreateTestEntityNameOutput", - "OnDeleteTestEntityNameByIdInput": "OnDeleteTestEntityNameByIdInput", "OnDeleteTestEntityNameInput": "OnDeleteTestEntityNameInput", "OnDeleteTestEntityNameOutput": "OnDeleteTestEntityNameOutput", - "OnUpdateTestEntityNameByIdInput": "OnUpdateTestEntityNameByIdInput", "OnUpdateTestEntityNameInput": "OnUpdateTestEntityNameInput", "OnUpdateTestEntityNameInstanceInput": "OnUpdateTestEntityNameInstanceInput", "OnUpdateTestEntityNameInstanceNestedInput": "OnUpdateTestEntityNameInstanceNestedInput",