Magento has an out of the box GraphQl feature that will be useful for the storefront API to interact with third-party software.
Sometimes you have checked the syntax of FilterEqualTypeInput and FilterMatchTypeInput in a schema.graphql file of the Graphql module.
This syntax is used to filter the GraphQl Query with Custom Attribute type.
1) FilterEqualTypeInput
It’s an input parameter with
equal
and match
type to filter out the response of the GraphQl based on the specified criteria.
Keep in mind, Select, Multi-Select, and Boolean Attribute type used to filter with Equal type Input.
input FilterEqualTypeInput @doc(description: "Defines a filter that matches the input exactly.") { in: [String] @doc(description: "An array of values to filter on") eq: String @doc(description: "A string to filter on") }
Using Equal Input type, in and eq keyword is used to filter out the response on the GraphQl query.
in => You have to specify an array of the string parameters.
eq => Define String to filter out the response.
Example by use of the keyword "in"
with Product Graphql,
You have to add one or more comma-separated SKU with the in array to filter out the response, Each value must be in string format.
{ products(filter: { sku: { in: ["24-MB02","24-MB03","24-MB04"] } }) { items { id name sku short_description { html } stock_status } } }
Example by use of keyword "eq"
with product Graphql, Define SKU to search from the catalog,
{ products(filter: { sku: { eq: "24-MB03" } }) { items { id name sku short_description { html } stock_status } } }
2) FilterMatchTypeInput
Keep in mind, Attribute type with Text, Text Area Used to filter with Match type input.
input FilterMatchTypeInput @doc(description: "Defines a filter that performs a fuzzy search.") { match: String @doc(description: "One or more words to filter on") }
Using the Match Input type, the match keyword is used to filter out the response based on the match keyword from the GraphQl query.
Get Category list details by the match filter type,
categoryList(filters: { name: { match: "Gear" } }) { children_count children { name id position is_anchor } } }
I hope you have understood the use of match and equal filter type of GraphQl feature in Magento 2.
Product, Category, Sales Order, URL Rewrite, Requisition list, RMA, Negotiable Quote GraphQl supports the above filter type with their query.
You can check any of the above module’s schema.graphql
file to understand the filtration withing equal and match keyword.
You can find the base definition of the Filter type from the app/code/Magento/GraphQl/etc/schema.graphqls file.
Magento_GraphQl
is the base module for the GraphQl in Magento to all the basic syntax for the Filter the Custom Attribute type. The Core logic of each GraphQl module resides under this module.
You can learn about the new type, FilterRangeTypeInput in GraphQl Magento 2. Using Range Type, Filter the Response by the from and to Keywords.
Range Type will be used for the Date and Price related Attribute type.