Navigation Menu

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

Subscription [WIP] #158

Merged
merged 9 commits into from May 12, 2020
Merged

Subscription [WIP] #158

merged 9 commits into from May 12, 2020

Conversation

getlarge
Copy link
Contributor

Hey,

Just to keep you in touch with the progress made on the subscription, i open this PR.

Tomorrow i will have to pick a direction on how to compose the topic that PubSub instance will listen, so i started to add some specific properties to the Subscription class like delimiter, pattern and wildcard.

  • delimiter could be different, depending on the type of PubSub ( like / for MQTT or . for AMQP)
  • pattern will be a string containing the keys found in Entity Attributes that will be used for topic composition and separated by the delimiter
  • wildcard will be optional, and will also depend on the type of PubSub passed in the context. It would be used at the end of the topic and is treated like a catchall

When we'll try to resolve the GraphQL subscribe field (in getSubscriptionResolver function), the pattern will be splitted by the delimiter and each item ( attribute key) will be used to fill the topic.

@codecov-io
Copy link

codecov-io commented May 11, 2020

Codecov Report

Merging #158 into master will increase coverage by 0.13%.
The diff coverage is 72.01%.

@@            Coverage Diff             @@
##           master     #158      +/-   ##
==========================================
+ Coverage   72.93%   73.07%   +0.13%     
==========================================
  Files          50       52       +2     
  Lines        4186     4668     +482     
  Branches      768      860      +92     
==========================================
+ Hits         3053     3411     +358     
- Misses       1108     1224     +116     
- Partials       25       33       +8     

@chriskalmar
Copy link
Owner

looking forward to it 👍

Copy link
Contributor Author

@getlarge getlarge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here few comments to clarify this implementation of subscription and the doubts remaining

package.json Show resolved Hide resolved
@@ -973,6 +979,28 @@ const validatePermissionMutationTypes = (
}
};

const validatePermissionSubscriptionTypes = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied dumbly the check made for permission.mutation not sure it's needed for subscription.

src/engine/subscription/Subscription.spec.ts Show resolved Hide resolved
typeName,
entitySubscription,
) => {
if (entitySubscription.attributes && Object.keys(input).length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are allowed to use the preProcessor to generate a custom topic that will be used by PubSub instance in getSubscriptionResolver .
The default topic being ${entitySubscription.name}${entity.name}

src/engine/subscription/Subscription.spec.ts Show resolved Hide resolved
@@ -453,3 +457,170 @@ export const getMutationResolver = (
}
};
};

export const getSubscriptionResolver = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function used to generate the AsyncIterator that will be used to retrieve messages published by pubsub provided by Shyft or context.

};
};

export const getSubscriptionPayloadResolver = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function used to reformat the payload published by Pubsub.

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

const i18nInputFieldTypesCache = {};

Copy link
Contributor Author

@getlarge getlarge May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of code duplicated from mutation ; maybe some refactor might be needed by providing generic functions usable for subscription and mutation.

return instanceId;
};

export const generateSubscriptions = graphRegistry => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference with mutation resides in the field return in the subscription map, as GraphQL specify a Subscription field with type, description, args, subscribe (returning the AsyncIterator), and an optional resolve.

SUBSCRIPTION_TYPE_CREATE,
SUBSCRIPTION_TYPE_UPDATE,
SUBSCRIPTION_TYPE_DELETE,
pubsub,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export Pubsub instance for testing purpose.

@chriskalmar chriskalmar merged commit c90e154 into chriskalmar:master May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants