-
Notifications
You must be signed in to change notification settings - Fork 89
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
refactor: made webhook event type an enum in GraphQL schema #3025
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
@BlairCurrey would be good to get another perspective as well: what do you think about the issue? I like having a proper enum to be used in the graphql query, but knowing that GQL unfortunately only supports upper snake case values like @oana-lolea mentioned, could it be confusing if people try to use the generated enum value when handing the webhook events in the webhook service, since it won't match up? |
I think it would be problematic. We couldn't use them for identifying which type of webhook was received (ie What about a custom scalar? const WebhookEventType = new GraphQLScalarType({
name: 'WebhookEventType',
description: 'Webhook event type format (e.g., incoming_payment.created)',
serialize(value) {
return value;
},
parseValue(value) {
const allowedTypes = [
'incoming_payment.created',
'outgoing_payment.completed',
// Add other valid event types
];
if (!allowedTypes.includes(value)) {
throw new Error('Invalid WebhookEventType');
}
return value;
}
}); I guess this might not be clear on the auto-generated documentation side though (it will just show |
From the meeting: Let's try to update the Otherwise, we can keep the scalar. |
@mkurapov The scalar cannot be used for the filter because it can only be used within the GraphQL schema. We could however use its parser to validate the filter string values. |
@oana-lolea ah, I see. Thanks for taking a look into this. Since we can't use it as part of the filter (which would be useful for automatically validating user/client input), maybe we can just close this issue as not planned, and standardize all our enums separately in the future |
Changes proposed in this pull request
WebhookEventType
scalar in GraphQL schemaContext
Made
WebhookEvent
type a scalar instead of a string in GraphQL schema.Webhook event types format (e.g.
incoming_payment.created
) are accepted. Given a string with the webhook event type, the mapper returns its correspondingWebhookEventType
enum member, or throws an error if it doesn't exist.Fixes #2786
Checklist
fixes #number
user-docs
label (if necessary)