Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit deab5a4

Browse files
authored
first draft (#5438)
1 parent b80bd28 commit deab5a4

File tree

2 files changed

+149
-14
lines changed

2 files changed

+149
-14
lines changed

guides/v2.3/graphql/index.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,3 @@ GraphiQL is an in-browser tool for writing, validating, and testing GraphQL quer
4848
![GraphiQL browser]({{ page.baseurl }}/graphql/images/graphql-browser.png)
4949

5050
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.

guides/v2.3/graphql/queries.md

Lines changed: 149 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A query contains the following elements:
2828

2929
The following example shows the structure of the `cart` query:
3030

31-
```text
31+
```graphql
3232
query myCartQuery{
3333
cart(cart_id: String!): Cart
3434
}
@@ -38,7 +38,7 @@ In the preceding example, `myCartQuery` identifies your implementation of the `c
3838

3939
Now let's fully define a query:
4040

41-
```text
41+
```graphql
4242
query myCartQuery{
4343
cart(cart_id: "1WxKm8WUm3uFKXLlHXezew5WREfVRPAn") {
4444
items {
@@ -90,7 +90,7 @@ The following example shows the query response:
9090
}
9191
```
9292

93-
{:.bs-callout .bs-callout-tip}
93+
{:.bs-callout-tip}
9494
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.
9595

9696
## Query variables
@@ -103,7 +103,7 @@ Specifying variables in a query can help increase code re-use. Consider the foll
103103

104104
The following example declares the `$cart_id` variable. It is referenced in the `input` statement.
105105

106-
```text
106+
```graphql
107107
query myCartQueryWithVariable($cart_id: String!) {
108108
cart(cart_id: $cart_id) {
109109
items {
@@ -132,6 +132,144 @@ Variables are defined separately in JSON:
132132
}
133133
```
134134

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+
query IntrospectionQuery {
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+
query IntrospectionQuery {
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+
135273
## Product search queries
136274

137275
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
157295

158296
Each object type defines which fields can be searched. See the object-specific documentation for details.
159297

160-
{:.bs-callout .bs-callout-info}
298+
{:.bs-callout-info}
161299
You cannot specify the same search field twice in a GraphQL query.
162300

163301
#### Condition types and search values
@@ -201,7 +339,7 @@ The `sort` object allows you to specify which field or fields to use for sorting
201339

202340
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.
203341

204-
``` text
342+
```graphql
205343
sort: {
206344
price: DESC
207345
name: ASC
@@ -216,7 +354,7 @@ The following sections provide examples of each type of search. These examples u
216354

217355
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.
218356

219-
``` text
357+
```graphql
220358
{
221359
products(
222360
search: "Yoga pants"
@@ -256,7 +394,7 @@ The following sample query returns a list of products that meets the following c
256394

257395
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.
258396

259-
``` text
397+
```graphql
260398
{
261399
products(
262400
search: "Messenger"
@@ -348,7 +486,7 @@ The query returns the following:
348486

349487
The following search finds all products that were added after the specified time (midnight, November 1, 2017).
350488

351-
``` text
489+
```graphql
352490
{
353491
products(
354492
filter: {
@@ -387,7 +525,7 @@ The following search finds all products that were added after the specified time
387525

388526
The following example searches for all products whose `sku` begins with the string `24-MB` or whose `name` ends with `Bag`.
389527

390-
``` text
528+
```graphql
391529
{
392530
products(
393531
filter: {
@@ -433,7 +571,7 @@ The query returns 8 items.
433571

434572
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.
435573

436-
``` text
574+
```graphql
437575
{
438576
products(
439577
filter: {

0 commit comments

Comments
 (0)