I will show how you can build your GraphQL for Magento 2.3 and extend them with a filter logic. Our use case is a Pickup from Store endpoint what our frontend team needs to create an interactive map.
We are hire ! Wanna work for one of Germany’s leading Magento partners? With agile methods, small teams and big clients? We’re currently looking for experienced PHP & Magento developers in Munich/Rosenheim. Sounds interesting? Just drop me a line via [email protected]
In the story, we have the following acceptance criteria.
As a frontend developer, I need Endpoint to search for the next Pickup Store in a Postcode Area. Use a setup script initial import Allow search for Postcode or Name. API will return the following attributes for a Pickup Store
Arrribute Name | GraphQL field |
---|---|
Name | name |
Postcode | postcode |
Street | street |
Street Number | street_num |
City | city |
Longitude | longitude |
Latitude | latitude |
- Create new Table with Declarative Schema
- Use Data Patch to import Sample Data
- Implement own GraphQL Endpoint with Filter Query
- Magento 2.3.3
* = in production please use the --keep-generated
option
- Unzip the zip file in to
app/code/LarsRoettig/GraphQLStorePickup
- Enable the module by running
php bin/magento module:enable LarsRoettig_GraphQLStorePickup
- Apply database updates by running
php bin/magento setup:upgrade
* - Flush the cache by running
php bin/magento cache:flush
- Install the module composer by running
composer require larsroettig/module-graphqlstorepickup
- enable the module by running
php bin/magento module:enable LarsRoettig_GraphQLStorePickup
- apply database updates by running
php bin/magento setup:upgrade
* - Flush the cache by running
php bin/magento cache:flush
Simple Query without an filter:
{
pickUpStores {
total_count
items {
name
street
street_num
postcode
}
}
}
Query with an filter:
{
pickUpStores(
filter: { name: { like: "Brick and Mortar 1%" } }
pageSize: 2
currentPage: 1
) {
total_count
items {
name
street
postcode
}
}
}