You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
To begin using GraphiQL, set the GraphQL endpoint by entering `http://<magento2-3-server>/graphql` in the URL bar, then click **Set endpoint**. You can use the browser in the right column to determine how to set up a query. Additional examples are also available in [Queries]({{ page.baseurl }}/graphql/queries.html).
51
-
52
-
{:.bs-callout .bs-callout-info}
53
-
You can access the GraphQL introspection feature only if your Magento instance is in developer mode. [Set the Magento mode]({{ page.baseurl }}/config-guide/cli/config-cli-subcommands-mode.html) describes how to check and change the mode.
@@ -90,7 +90,7 @@ The following example shows the query response:
90
90
}
91
91
```
92
92
93
-
{:.bs-callout .bs-callout-tip}
93
+
{:.bs-callout-tip}
94
94
Magento will not run a query that is too complex. The number of fields, objects, and nodes are factors in determining the complexity of a query.
95
95
96
96
## Query variables
@@ -103,7 +103,7 @@ Specifying variables in a query can help increase code re-use. Consider the foll
103
103
104
104
The following example declares the `$cart_id` variable. It is referenced in the `input` statement.
105
105
106
-
```text
106
+
```graphql
107
107
querymyCartQueryWithVariable($cart_id: String!) {
108
108
cart(cart_id: $cart_id) {
109
109
items {
@@ -132,6 +132,144 @@ Variables are defined separately in JSON:
132
132
}
133
133
```
134
134
135
+
## Introspection queries
136
+
137
+
Introspection queries allow you to return information about the schema. For example, you might want a list of Magento GraphQL queries or details about a specific data type. The GraphQL specification determines the structure of introspection queries. See [Introspection](https://graphql.org/learn/introspection/) for more information.
138
+
139
+
For Magento, introspection queries MUST have the operation name `IntrospectionQuery`. If you omit the operation name, or use a different name, the query returns incomplete results.
140
+
141
+
### Example introspection queries
142
+
143
+
#### Return a list of Magento queries
144
+
145
+
The following query returns a list of Magento queries. The results are truncated.
146
+
147
+
**Request**
148
+
149
+
```graphql
150
+
queryIntrospectionQuery {
151
+
__schema {
152
+
mutationType {
153
+
fields {
154
+
name
155
+
description
156
+
}
157
+
}
158
+
}
159
+
}
160
+
```
161
+
162
+
**Response**
163
+
164
+
```json
165
+
{
166
+
"data": {
167
+
"__schema": {
168
+
"queryType": {
169
+
"fields": [
170
+
{
171
+
"name": "cart",
172
+
"description": "Returns information about shopping cart"
173
+
},
174
+
{
175
+
"name": "category",
176
+
"description": "The category query searches for categories that match the criteria specified in the search and filter attributes."
177
+
}
178
+
]
179
+
}
180
+
}
181
+
}
182
+
}
183
+
```
184
+
185
+
### Get details about a data type
186
+
187
+
The following introspection query returns details about the `ProductAttributeFilterInput` data type.
188
+
189
+
**Request**
190
+
191
+
```graphql
192
+
queryIntrospectionQuery {
193
+
__type(name: "ProductAttributeFilterInput") {
194
+
name
195
+
kind
196
+
description
197
+
inputFields {
198
+
name
199
+
description
200
+
defaultValue
201
+
}
202
+
fields {
203
+
name
204
+
args {
205
+
name
206
+
description
207
+
type {
208
+
kind
209
+
name
210
+
}
211
+
}
212
+
type {
213
+
kind
214
+
name
215
+
}
216
+
}
217
+
}
218
+
}
219
+
```
220
+
221
+
**Response**
222
+
223
+
```json
224
+
{
225
+
"data": {
226
+
"__type": {
227
+
"name": "ProductAttributeFilterInput",
228
+
"kind": "INPUT_OBJECT",
229
+
"description": "ProductAttributeFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.",
230
+
"inputFields": [
231
+
{
232
+
"name": "category_id",
233
+
"description": "Filter product by category id",
234
+
"defaultValue": null
235
+
},
236
+
{
237
+
"name": "description",
238
+
"description": "Attribute label: Description",
239
+
"defaultValue": null
240
+
},
241
+
{
242
+
"name": "name",
243
+
"description": "Attribute label: Product Name",
244
+
"defaultValue": null
245
+
},
246
+
{
247
+
"name": "price",
248
+
"description": "Attribute label: Price",
249
+
"defaultValue": null
250
+
},
251
+
{
252
+
"name": "short_description",
253
+
"description": "Attribute label: Short Description",
254
+
"defaultValue": null
255
+
},
256
+
{
257
+
"name": "sku",
258
+
"description": "Attribute label: SKU",
259
+
"defaultValue": null
260
+
},
261
+
{
262
+
"name": "url_key",
263
+
"description": "The part of the URL that identifies the product",
264
+
"defaultValue": null
265
+
}
266
+
],
267
+
"fields": null
268
+
}
269
+
}
270
+
}
271
+
```
272
+
135
273
## Product search queries
136
274
137
275
A product search query can contain the following components:
@@ -157,7 +295,7 @@ Search filters are logically ANDed unless an `or` statement is specified. The se
157
295
158
296
Each object type defines which fields can be searched. See the object-specific documentation for details.
159
297
160
-
{:.bs-callout .bs-callout-info}
298
+
{:.bs-callout-info}
161
299
You cannot specify the same search field twice in a GraphQL query.
162
300
163
301
#### Condition types and search values
@@ -201,7 +339,7 @@ The `sort` object allows you to specify which field or fields to use for sorting
201
339
202
340
In the following example, Magento returns a list of items that are sorted in order of decreasing price. If two or more items have the same price, the items are listed in alphabetic order by name.
203
341
204
-
```text
342
+
```graphql
205
343
sort: {
206
344
price: DESC
207
345
name: ASC
@@ -216,7 +354,7 @@ The following sections provide examples of each type of search. These examples u
216
354
217
355
The following search returns items that contain the word `yoga` or `pants`. The Catalog Search index contains search terms taken from the product `name`, `description`, `short_description` and related attributes.
218
356
219
-
```text
357
+
```graphql
220
358
{
221
359
products(
222
360
search: "Yoga pants"
@@ -256,7 +394,7 @@ The following sample query returns a list of products that meets the following c
256
394
257
395
The response for each item includes the `name`, `sku`, `price` and `description` only. Up to 25 results are returned at a time, in decreasing order of price.
258
396
259
-
```text
397
+
```graphql
260
398
{
261
399
products(
262
400
search: "Messenger"
@@ -348,7 +486,7 @@ The query returns the following:
348
486
349
487
The following search finds all products that were added after the specified time (midnight, November 1, 2017).
350
488
351
-
```text
489
+
```graphql
352
490
{
353
491
products(
354
492
filter: {
@@ -387,7 +525,7 @@ The following search finds all products that were added after the specified time
387
525
388
526
The following example searches for all products whose `sku` begins with the string `24-MB` or whose `name` ends with `Bag`.
389
527
390
-
```text
528
+
```graphql
391
529
{
392
530
products(
393
531
filter: {
@@ -433,7 +571,7 @@ The query returns 8 items.
433
571
434
572
This query searches for products that have `name` that ends with `Short` or has a `sku` that indicates the product is a pair of women’s pants (`WP%`). The system performs a logical AND to restrict the results to those that cost from $40 to $49.99.
0 commit comments