Skip to content

larsroettig-dev/module-graphqlstorepickup

Repository files navigation

Scrutinizer Code Quality Code Coverage Build Status

Magento Module LarsRoettig_GraphQLStorePickup

Main Functionalities

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
❗ The Code is not for a production server it is only proof of concept imeplementation ❗

Features

  • Create new Table with Declarative Schema
  • Use Data Patch to import Sample Data
  • Implement own GraphQL Endpoint with Filter Query

Tested on Version

  • Magento 2.3.3

Installation

* = in production please use the --keep-generated option

Type 1: Zip file

  • 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

Type 2: Composer

  • 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

How to use it

Possibly Query (https://your_domain.test/graphql)

GraphQL_Playground

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
    }
  }
}