This repository demonstrates a production-ready pattern for binding GraphQL data to Syncfusion Blazor DataGrid using Hot Chocolate GraphQL Server. The sample application provides complete CRUD (Create, Read, Update, Delete) operations, filtering, sorting, paging, grouping, and batch updates. The implementation follows industry best practices using GraphQL queries, mutations, resolvers, and a GraphQL adaptor for seamless grid functionality.
- Hot Chocolate GraphQL Server Integration: Query resolvers for read operations and mutation resolvers for write operations
- Syncfusion Blazor DataGrid: Built-in search, filter, sort, paging, and grouping capabilities
- Complete CRUD Operations: Add, edit, delete, and batch update expense records directly from the grid
- GraphQL Adaptor: Full control over grid data operations (read, search, filter, sort, page, group) via GraphQL queries and mutations
- DataManagerRequestInput: Structured input type for handling complex data operations from the DataGrid
- Configurable GraphQL Endpoint: Backend port and GraphQL endpoint managed via
launchSettings.json
| Component | Version | Purpose |
|---|---|---|
| Visual Studio 2022 | 17.0 or later | Development IDE with Blazor workload |
| .NET SDK | net8.0 or compatible | Runtime and build tools |
| HotChocolate.AspNetCore | 15.1 or later | GraphQL server framework |
| Syncfusion.Blazor.Grid | Latest | DataGrid and UI components |
| Syncfusion.Blazor.Themes | Latest | Styling for DataGrid components |
| Syncfusion.Blazor.Data | Latest | Data adaptors including GraphQL support |
-
Clone the repository
git clone <repository-url> cd "Binding-data-from-remote-service-to-blazor-data-grid" cd "GraphQLAdaptor/Grid_GraphQLAdaptor"
-
Restore packages and build
dotnet restore; dotnet build
-
Run the application
dotnet run
-
Open the application
Navigate to the local URL displayed in the terminal (typically
https://localhost:7272orhttp://localhost:5272). -
Access GraphQL Playground (Optional)
Navigate to
https://localhost:7272/graphqlto explore the GraphQL schema and test queries/mutations manually.
The GraphQL endpoint port is configured in Properties/launchSettings.json. This file controls where the application runs and where the GraphQL endpoint is exposed.
Instructions to Change the Port:
- Open
Properties/launchSettings.jsonin the project root. - Locate the
httpsprofile section:
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7272;http://localhost:5272",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}-
Modify the
applicationUrlproperty to change port numbers:https://localhost:7272- HTTPS port for GraphQL endpointhttp://localhost:5272- HTTP port for GraphQL endpoint
-
Update the DataGrid connection URL in
Components/Pages/Home.razorto match the configured port:<SfDataManager Url="https://localhost:7272/graphql" GraphQLAdaptorOptions="@adaptorOptions" Adaptor="Adaptors.GraphQLAdaptor"></SfDataManager>
Important Notes:
- Port numbers must be between 1024 and 65535
- Avoid using ports already in use by other applications
- The GraphQL endpoint is always accessible at
/graphqlpath (configured viaapp.MapGraphQL()in Program.cs)
The GraphQLAdaptorOptions in Home.razor defines how the DataGrid communicates with the GraphQL backend. This configuration specifies:
- Query: GraphQL query for reading expense records with data operations support
- ResolverName: Backend resolver method name (e.g.,
expenseRecordData) - Mutation.Insert: GraphQL mutation for creating new records
- Mutation.Update: GraphQL mutation for updating existing records
- Mutation.Delete: GraphQL mutation for deleting records
- Mutation.Batch: GraphQL mutation for batch operations (multiple add/edit/delete)
Refer to the Full Documentation for complete GraphQL adaptor configuration examples.
| File/Folder | Purpose |
|---|---|
/Models/ExpenseRecord.cs |
Data model representing expense records |
/Models/GraphQLQuery.cs |
Query resolvers for read operations (GetExpenseRecordData) |
/Models/GraphQLMutation.cs |
Mutation resolvers for write operations (CreateExpense, UpdateExpense, DeleteExpense, BatchUpdate) |
/Models/DataManagerRequestInput.cs |
Input type for data operation parameters (filter, sort, search, paging) |
/Components/Pages/Home.razor |
DataGrid page with GraphQL adaptor configuration and expense management UI |
/Program.cs |
Service registration for Hot Chocolate GraphQL server |
/Properties/launchSettings.json |
Port configuration for GraphQL endpoint |
- Click the Add button in the toolbar
- Fill in the form fields (Employee Name, Amount, Category, Status, etc.)
- Upload an employee avatar image (optional)
- Click Update to create the record via GraphQL mutation
- The system automatically generates a unique ExpenseId (e.g., EXP001)
- Select a row in the grid
- Click the Edit button in the toolbar or double-click the row
- Modify the required fields in the dialog
- Click Update to save changes via GraphQL mutation
- Total amount is automatically recalculated based on Amount and Tax Percentage
- Select a row in the grid
- Click the Delete button in the toolbar
- Confirm the deletion in the dialog
- The record is removed via GraphQL mutation
- Use the Search box in the toolbar
- Enter keywords to filter records (searches across all columns)
- The search query is sent to the backend via GraphQL with field specifications
- Click the filter icon in any column header
- Select filter criteria (equals, contains, greater than, etc.)
- Click Filter to apply
- The filter conditions are sent to the backend as GraphQL predicate objects
- Click the column header to sort ascending
- Click again to sort descending
- Hold Ctrl and click additional headers for multi-level sorting
- Sort specifications are sent to the backend via GraphQL
- Drag a column header to the group drop area above the grid
- Click the group header to expand or collapse groups
- Group fields are sent to the backend via the GraphQL data manager request
- Make multiple changes to different rows (add, edit, delete)
- Click Update to apply all changes in a single operation
- The batch mutation sends all changed, added, and deleted records to the backend in one request
- Verify the application is running: Check terminal for
Now listening on: https://localhost:xxxx - Confirm the URL in
SfDataManagermatches the running port - Ensure
app.MapGraphQL()is configured inProgram.cs - Check firewall settings if accessing from a different machine
- Verify Syncfusion stylesheet is referenced in
Components/App.razor:<link href="_content/Syncfusion.Blazor.Themes/tailwind3.css" rel="stylesheet" />
- Verify Syncfusion scripts are referenced in
Components/App.razor:<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
- Check browser developer tools (F12) for 404 errors on static resources
- Verify the GraphQL endpoint URL in
Home.razorSfDataManager matches the backend port - Check browser console for GraphQL errors (Network tab → GraphQL requests)
- Ensure all GraphQL mutation resolvers are implemented in
GraphQLMutation.cs - Verify the
DataManagerRequestInputclass includes all required properties for data operations
- Align HotChocolate.AspNetCore and Syncfusion package versions
- Run
dotnet restoreto update NuGet packages - Check the
Grid_GraphQLAdaptor.csprojfile for conflicting version constraints - Verify all packages are compatible with .NET 8.0 or later
- Change the port numbers in
launchSettings.jsonto available ports - Or identify the process using the port:
Get-Process | Where-Object {$_.Handles -gt 500} | Select-Object Name, Id - Update the DataGrid connection URL to match the new port
Detailed, step-by-step directions including complete code examples, GraphQL query structures, mutation implementations, and advanced configurations are available in the user guide.