ashokdubariya / module-testimonial
Magento 2 Testimonial Module with GraphQL API support and Hyvä Theme compatibility for managing customer testimonials with complete CRUD operations, admin panel, and frontend display.
Package info
github.com/ashokdubariya/magento2-testimonial-graphql
Type:magento2-module
pkg:composer/ashokdubariya/module-testimonial
Requires
- php: ^8.1
- magento/framework: ^103.0
- magento/module-backend: ^102.0
- magento/module-ui: ^101.2
Suggests
- hyva-themes/magento2-default-theme: Required for Hyva theme compatibility (^1.1)
README
This repository contains a Testimonial module with GraphQL API support and Hyvä Theme compatibility for managing customer testimonials with complete CRUD operations, admin panel, and frontend display.
Key Features
- Complete database schema with optimized indexes
- Full Admin CRUD using Magento UI Components
- Frontend testimonial listing and submission pages
- GraphQL endpoints (queries & mutations)
- Strong validation and security best practices
- LESS-based styling following Magento 2 standards (Luma)
- Hyvä theme compatible frontend (no RequireJS / no jQuery)
- Repository pattern and service layer architecture
Requirements
- Magento Open Source 2.4.5+
- PHP 8.1+
Module Information
- Module Name:
Ashokdubariya_Testimonial - Package Name:
ashokdubariya/module-testimonial - Module Type: Magento 2 Custom Module
- API Type: GraphQL
- License: MIT
Installation
Method 1: Composer Installation (Recommended)
composer require ashokdubariya/module-testimonial php bin/magento module:enable Ashokdubariya_Testimonial php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
Method 2: Manual Installation
- Copy the module to Magento:
mkdir -p app/code/Ashokdubariya/Testimonial
# Copy module files to app/code/Ashokdubariya/Testimonial
- Run Magento commands:
php bin/magento module:enable Ashokdubariya_Testimonial php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush
GraphQL Endpoint
After installation, the GraphQL endpoint is available at:
https://your-magento-site.com/graphql
GraphQL Schema Example
File: etc/schema.graphqls
Queries
1. Get All Testimonials (with Filtering & Pagination)
Basic Query
query { testimonials(currentPage: 1, pageSize: 10) { total_count items { testimonial_id customer_name customer_email message rating status created_at updated_at } } }
With Filters - Filter by Status
query { testimonials( currentPage: 1 pageSize: 10 filter: { status: { eq: "1" } } ) { total_count items { testimonial_id customer_name message rating created_at } } }
With Filters - Filter by Rating
query { testimonials( filter: { rating: { eq: "5" } } ) { total_count items { testimonial_id customer_name message rating } } }
With Filters - Search by Name (LIKE)
query { testimonials( filter: { customer_name: { like: "John" } } ) { total_count items { testimonial_id customer_name message } } }
With Filters - Multiple Ratings (IN)
query { testimonials( filter: { rating: { in: ["4", "5"] } } ) { total_count items { testimonial_id customer_name rating } } }
With Filters - Date Range
query { testimonials( filter: { created_at: { from: "2026-01-01" to: "2026-01-31" } } ) { total_count items { testimonial_id customer_name created_at } } }
With Filters - Combined Filters
query { testimonials( currentPage: 1 pageSize: 20 filter: { status: { eq: "1" } rating: { in: ["4", "5"] } customer_name: { like: "John" } } ) { total_count items { testimonial_id customer_name message rating status created_at } } }
2. Get Testimonial by ID
query { testimonial(id: 5) { testimonial_id customer_name customer_email message rating status created_at updated_at } }
Response
{
"data": {
"testimonial": {
"testimonial_id": 5,
"customer_name": "John Doe",
"customer_email": "john@example.com",
"message": "Excellent service!",
"rating": 5,
"status": 1,
"created_at": "2026-01-06 15:00:00",
"updated_at": "2026-01-06 16:30:00"
}
}
}
Mutations
3. Add Testimonial
mutation { addTestimonial( input: { customer_name: "John Doe" customer_email: "john@example.com" message: "Excellent service! Highly recommended." rating: 5 } ) { testimonial_id status message } }
Response
{
"data": {
"addTestimonial": {
"testimonial_id": 6,
"status": "success",
"message": "Testimonial submitted successfully. It will be reviewed by our team."
}
}
}
4. Update Testimonial
Update one or more fields of an existing testimonial.
Update All Fields
mutation { updateTestimonial( id: 5 input: { customer_name: "John Smith" customer_email: "john.smith@example.com" message: "Updated message - Still excellent!" rating: 5 status: 1 } ) { testimonial_id status message testimonial { testimonial_id customer_name customer_email message rating status updated_at } } }
Update Specific Fields Only
mutation { updateTestimonial( id: 5 input: { status: 1 } ) { testimonial_id status message testimonial { testimonial_id status updated_at } } }
Update Rating and Message
mutation { updateTestimonial( id: 5 input: { message: "Updated testimonial message" rating: 4 } ) { testimonial_id status message } }
Response
{
"data": {
"updateTestimonial": {
"testimonial_id": 5,
"status": "success",
"message": "Testimonial updated successfully.",
"testimonial": {
"testimonial_id": 5,
"customer_name": "John Smith",
"customer_email": "john.smith@example.com",
"message": "Updated message - Still excellent!",
"rating": 5,
"status": 1,
"updated_at": "2026-01-06 16:50:00"
}
}
}
}
5. Delete Testimonial
mutation { deleteTestimonial(id: 5) { status message } }
Response
{
"data": {
"deleteTestimonial": {
"status": "success",
"message": "Testimonial deleted successfully."
}
}
}
Error Response (Not Found)
{
"errors": [
{
"message": "Testimonial with ID 999 not found.",
"extensions": {
"category": "graphql-no-such-entity"
}
}
]
}
Filter Options
Available Filter Fields
customer_name- Filter by customer namecustomer_email- Filter by emailrating- Filter by rating (1-5)status- Filter by status (0=Disabled, 1=Enabled)created_at- Filter by creation date
Filter Types
| Filter Type | Description | Example |
|---|---|---|
eq |
Equal to | { eq: "1" } |
in |
In array | { in: ["4", "5"] } |
like |
Pattern match | { like: "John" } |
from |
Greater than or equal | { from: "2026-01-01" } |
to |
Less than or equal | { to: "2026-01-31" } |
cURL Examples
Get Filtered Testimonials
curl -X POST https://your-magento-site.com/graphql \ -H "Content-Type: application/json" \ -d '{ "query": "query { testimonials(filter: { status: { eq: \"1\" }, rating: { in: [\"4\", \"5\"] } }) { total_count items { testimonial_id customer_name rating } } }" }'
Update Testimonial
curl -X POST https://your-magento-site.com/graphql \ -H "Content-Type: application/json" \ -d '{ "query": "mutation { updateTestimonial(id: 5, input: { status: 1 }) { testimonial_id status message } }" }'
Delete Testimonial
curl -X POST https://your-magento-site.com/graphql \ -H "Content-Type: application/json" \ -d '{ "query": "mutation { deleteTestimonial(id: 5) { status message } }" }'
Common Use Cases
1. Get Only 5-Star Testimonials
query { testimonials(filter: { rating: { eq: "5" }, status: { eq: "1" } }) { items { customer_name message created_at } } }
2. Get Recent Testimonials (Last 30 Days)
query { testimonials( filter: { created_at: { from: "2025-12-07" } status: { eq: "1" } } ) { items { customer_name message rating created_at } } }
3. Search Testimonials by Customer Email
query { testimonials(filter: { customer_email: { like: "@example.com" } }) { items { testimonial_id customer_name customer_email message } } }
4. Approve Testimonial (Change Status)
mutation { updateTestimonial(id: 10, input: { status: 1 }) { status message testimonial { testimonial_id status } } }
5. Bulk Approve by Getting Disabled and Updating
# Step 1: Get disabled testimonials query { testimonials(filter: { status: { eq: "0" } }) { items { testimonial_id customer_name message } } } # Step 2: Update each one mutation { updateTestimonial(id: 10, input: { status: 1 }) { status message } }
Validation Rules
Add/Update Testimonial
- customer_name: Required (for add), max 255 characters
- customer_email: Required (for add), valid email format, max 255 characters
- message: Required (for add), no length limit
- rating: Required (for add), integer 1-5
- status: Optional, 0 or 1
Filter Values
- All filter values should be strings (even numbers)
- Date format:
YYYY-MM-DDorYYYY-MM-DD HH:MM:SS - Use
likefor partial matches (automatically adds % wildcards)
Status Values
0= Disabled (default for customer submissions)1= Enabled (visible in public queries)
Complete API Summary
| Operation | Type | Description |
|---|---|---|
testimonials |
Query | Get paginated list with filtering |
testimonial |
Query | Get single testimonial by ID |
addTestimonial |
Mutation | Create new testimonial |
updateTestimonial |
Mutation | Update existing testimonial |
deleteTestimonial |
Mutation | Delete testimonial |
Testing with GraphQL Playground
- Navigate to:
https://your-magento-site.com/graphql - Use the schema explorer to see all available fields
- Test queries and mutations interactively
- View auto-complete suggestions
Additional Resources
- Admin Panel:
/admin/testimonial/testimonial/index - Frontend Listing:
/testimonial - Submit Form:
/testimonial/submit - Module Location:
/app/code/Ashokdubariya/Testimonial
Support
- Source: GitHub Repository
- Issues: GitHub Issues
License
This project is licensed under the MIT License - see the LICENSE file for details.