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

Change subscription attributes presence checks #161

Merged
merged 1 commit into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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