Skip to content

Commit

Permalink
Change subscription attributes presence checks
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed May 13, 2020
1 parent 6b628cd commit e8472d5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/engine/subscription/Subscription.spec.ts
Expand Up @@ -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',
Expand Down
40 changes: 20 additions & 20 deletions src/engine/subscription/Subscription.ts
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -9,6 +9,7 @@ Subscription {
],
"delimiter": "/",
"description": "build item",
"ignoreRequired": true,
"isTypeCreate": true,
"name": "SomeSubWithPostProcessor",
"postProcessor": [Function],
Expand Down Expand Up @@ -67,6 +68,7 @@ Subscription {
],
"delimiter": "/",
"description": "build item",
"ignoreRequired": true,
"isTypeCreate": true,
"name": "SomeSubWithPreProcessor",
"preProcessor": [Function],
Expand Down
2 changes: 0 additions & 2 deletions src/graphqlProtocol/__snapshots__/generator.spec.ts.snap
Expand Up @@ -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",
Expand Down

0 comments on commit e8472d5

Please sign in to comment.