Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add pubsub from graphql-subscriptions ; whitelist entity.susbcription…
…s prop
  • Loading branch information
getlarge committed May 12, 2020
1 parent ccce3ab commit 7c64a45
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -87,6 +87,7 @@
"date-fns": "^2.1.0",
"graphql": "^14.5.8",
"graphql-relay": "^0.6.0",
"graphql-subscriptions": "^1.1.0",
"graphql-type-json": "^0.3.0",
"json-shaper": "^1.2.0",
"lodash": "^4.17.10",
Expand Down
2 changes: 1 addition & 1 deletion src/engine/constants.ts
Expand Up @@ -47,6 +47,7 @@ export const entityPropertiesWhitelist: Array<string> = [
'includeUserTracking',
'indexes',
'mutations',
'subscriptions',
'permissions',
'states',
'preProcessor',
Expand Down Expand Up @@ -118,4 +119,3 @@ export const shadowEntityAttributePropertiesWhitelist: Array<string> = [
'primary',
'meta',
];

16 changes: 10 additions & 6 deletions src/engine/subscription/Subscription.ts
@@ -1,8 +1,11 @@
import { uniq } from 'lodash';
import { PubSub } from 'graphql-subscriptions';
import { passOrThrow, isArray, isFunction, mapOverProperties } from '../util';

import { Entity } from '../entity/Entity';

export const pubsub = new PubSub();

export const SUBSCRIPTION_TYPE_CREATE = 'onCreate';
export const SUBSCRIPTION_TYPE_UPDATE = 'onUpdate';
export const SUBSCRIPTION_TYPE_DELETE = 'onDelete';
Expand Down Expand Up @@ -53,7 +56,7 @@ export type SubscriptionSetup = {
entitySubscription?: Subscription,
context?: object,
info?: any,
) => Promise<object>;
) => Promise<object | null> | object | null;
postProcessor?: (
entity?: Entity,
// id,
Expand All @@ -63,7 +66,7 @@ export type SubscriptionSetup = {
entitySubscription?: Subscription,
context?: object,
info?: any,
) => Promise<object>;
) => Promise<object | null> | object | null;
};

export class Subscription {
Expand Down Expand Up @@ -296,11 +299,12 @@ export const processEntitySubscriptions = (
() =>
`Subscription '${entity.name}.${subscription.name}' pattern should be a string`,
);
} else {
subscription.pattern = Object.keys(entityAttributes).join(
subscription.delimiter,
);
}
// else {
// subscription.pattern = Object.keys(entityAttributes).join(
// subscription.delimiter,
// );
// }
});

return subscriptions;
Expand Down
1 change: 0 additions & 1 deletion src/graphqlProtocol/subscription.ts
Expand Up @@ -8,7 +8,6 @@ import {
GraphQLInputFieldConfigMap,
GraphQLFieldConfigMap,
} from 'graphql';

import { fromGlobalId } from 'graphql-relay';
import * as _ from 'lodash';

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Expand Up @@ -50,6 +50,7 @@ import {
SUBSCRIPTION_TYPE_CREATE,
SUBSCRIPTION_TYPE_UPDATE,
SUBSCRIPTION_TYPE_DELETE,
pubsub,
} from './engine/subscription/Subscription';
import {
Permission,
Expand Down Expand Up @@ -227,6 +228,7 @@ export {
SUBSCRIPTION_TYPE_CREATE,
SUBSCRIPTION_TYPE_UPDATE,
SUBSCRIPTION_TYPE_DELETE,
pubsub,
Permission,
checkPermissionSimple,
buildPermissionFilter,
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Expand Up @@ -2861,6 +2861,13 @@ graphql-relay@^0.6.0:
dependencies:
prettier "^1.16.0"

graphql-subscriptions@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/graphql-subscriptions/-/graphql-subscriptions-1.1.0.tgz#5f2fa4233eda44cf7570526adfcf3c16937aef11"
integrity sha512-6WzlBFC0lWmXJbIVE8OgFgXIP4RJi3OQgTPa0DVMsDXdpRDjTsM1K9wfl5HSYX7R87QAGlvcv2Y4BIZa/ItonA==
dependencies:
iterall "^1.2.1"

graphql-type-json@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.0.tgz#bb32e1b74bf52ebc690f9df12b4067bc061f818a"
Expand Down Expand Up @@ -3404,6 +3411,11 @@ istanbul-reports@^3.0.0:
html-escaper "^2.0.0"
istanbul-lib-report "^3.0.0"

iterall@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea"
integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==

iterall@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7"
Expand Down

0 comments on commit 7c64a45

Please sign in to comment.