Skip to content

feat: webhook graphql types #206

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

Merged
merged 16 commits into from
May 26, 2025
Merged

feat: webhook graphql types #206

merged 16 commits into from
May 26, 2025

Conversation

theodesp
Copy link
Member

@theodesp theodesp commented May 22, 2025

Description

This PR introduces GraphQL type and mutation exposure for managing webhooks via WPGraphQL, allowing developers to query, create, and manage webhook configurations through the GraphQL API.

It also refactors the internal webhook registry and event system to better align with WordPress CPTs and metadata while improving consistency and testability.

Key changes:

  • ✨ Added GraphQL types and mutations for graphql_webhook post type management.
  • ✨ Exposed webhook creation and configuration via GraphQL mutations.
  • ✨ Enabled event registration only for webhook types that have a corresponding published CPT instance, enforcing permissions and active state at runtime.
  • 🔄 Refactored WebhookRegistry to cleanly separate type registration, CPT-based webhook creation, and event linkage.
  • 🔄 Standardized meta key usage (_webhook_event, _webhook_type, _webhook_config) to ensure proper event binding and active checks.
  • 🛠️ Improved event registry logic to validate and attach event hooks conditionally.
  • 📦 General code cleanup.

Related Issue

#169

Dependant PRs

  • None currently.

Type of Change

  • ✅ Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactoring (no functional changes)
  • 📄 Example update (no functional changes)
  • 📝 Documentation update
  • 🔍 Performance improvement
  • 🧪 Test update

How Has This Been Tested?

  • Manually tested GraphQL queries and mutations for creating, updating, and deleting graphql_webhook entries.
  • Verified event attachment only occurs for active CPT-backed webhooks.
  • Confirmed event trigger dispatch via native WordPress actions and GraphQL subscription/event monitor hooks.

Screenshots

Example

✅ Query: List all webhooks
graphql
Copy
Edit
query GetWebhooks {
graphqlWebhooks {
nodes {
id
databaseId
title
status
webhookType: webhookTypeFieldName
config: webhookConfigFieldName
}
}
}
Note: Replace webhookTypeFieldName and webhookConfigFieldName with the actual field names if you registered them via register_graphql_field.

✅ Mutation: Create a new webhook

mutation CreateWebhook {
  createWebhook(input: {
    title: "New Post Save Webhook"
    webhookType: "postsavedsubscriber"
    config: "{\"callback_url\":\"https://example.com/webhook-endpoint\"}"
  }) {
    graphqlWebhook {
      id
      databaseId
      title
      status
      webhookType
    }
  }
}

✅ Mutation: Update an existing webhook

mutation UpdateWebhook {
  updateWebhook(input: {
    id: "dGVzdDox"  # Replace with actual webhook ID
    title: "Updated Webhook Name"
    config: "{\"callback_url\":\"https://new-destination.com/endpoint\"}"
  }) {
    graphqlWebhook {
      id
      title
      config
    }
  }
}

✅ Mutation: Delete a webhook

mutation DeleteWebhook {
  deleteWebhook(input: { id: "dGVzdDox" }) {
    deletedId
    success
  }
}

✅ Query: Get a single webhook by ID

query GetWebhook {
  webhook(id: "dGVzdDox") {
    id
    title
    status
    webhookType
    config
  }
}

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's coding standards
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • Any dependent changes have been highlighted, merged or published

@theodesp theodesp changed the title Feat webhook graphql types feat: webhook graphql types May 22, 2025
@theodesp theodesp marked this pull request as ready for review May 23, 2025 13:52
@theodesp theodesp requested a review from a team as a code owner May 23, 2025 13:52
colinmurphy
colinmurphy previously approved these changes May 26, 2025
Copy link
Member

@colinmurphy colinmurphy left a comment

Choose a reason for hiding this comment

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

@theodesp LGTM ❤️ 🚀 🚀

@theodesp theodesp dismissed colinmurphy’s stale review May 26, 2025 08:30

The merge-base changed after approval.

colinmurphy
colinmurphy previously approved these changes May 26, 2025
@theodesp theodesp dismissed colinmurphy’s stale review May 26, 2025 11:11

The merge-base changed after approval.

colinmurphy
colinmurphy previously approved these changes May 26, 2025
@theodesp theodesp dismissed colinmurphy’s stale review May 26, 2025 11:26

The merge-base changed after approval.

@colinmurphy colinmurphy added this pull request to the merge queue May 26, 2025
Merged via the queue into main with commit a9216e1 May 26, 2025
5 checks passed
@colinmurphy colinmurphy deleted the feat-webhook-graphql-types branch May 26, 2025 11:26
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.

2 participants