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
Subscription [WIP] #158
Conversation
…ttern - wildcard to compose dynamically topic listened by pubsub
Codecov Report
@@ 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 |
looking forward to it 👍 |
…sing graphql.subscribe and pubsub
There was a problem hiding this 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
@@ -973,6 +979,28 @@ const validatePermissionMutationTypes = ( | |||
} | |||
}; | |||
|
|||
const validatePermissionSubscriptionTypes = ( |
There was a problem hiding this comment.
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.
typeName, | ||
entitySubscription, | ||
) => { | ||
if (entitySubscription.attributes && Object.keys(input).length) { |
There was a problem hiding this comment.
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}
@@ -453,3 +457,170 @@ export const getMutationResolver = ( | |||
} | |||
}; | |||
}; | |||
|
|||
export const getSubscriptionResolver = ( |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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 = {}; | ||
|
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
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
andwildcard
./
for MQTT or.
for AMQP)When we'll try to resolve the GraphQL
subscribe
field (ingetSubscriptionResolver
function), the pattern will be splitted by the delimiter and each item ( attribute key) will be used to fill the topic.