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.
Copy file name to clipboardExpand all lines: guides/v2.3/graphql/develop/create-graphqls-file.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ To illustrate how to configure the `schema.graphqls` file, let's suppose you hav
23
23
24
24
A query definition can be one line, or it can be complex. If your module's query implements `searchCriteria`, then you must define arguments that define filters and pagination information, all of which adds complexity. However, if you expect a single result from your query, then its definition can be simple.
25
25
26
-
The following example shows the `products` query. The `type` is defined as a `Query`. The `products` definitions define the keywords that are used to construct a query, as shown in [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html). The parameter definitions will be discussed in [Specify output attributes](#specify-output-attributes).
26
+
The following example shows the `products` query. The `type` is defined as a `Query`. The `products` definitions define the keywords that are used to construct a query, as shown in [Queries]({{ page.baseurl }}/graphql/queries.html). The parameter definitions will be discussed in [Specify output attributes](#specify-output-attributes).
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 at [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html).
54
+
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).
Copy file name to clipboardExpand all lines: guides/v2.3/graphql/mutations.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ title: Mutations
5
5
6
6
While GraphQL queries perform read operations, mutations change the data. A mutation can create, update, or delete objects and fields. In REST terminology, queries operate like `GET` requests, while mutations are similar to `POST`, `PUT`, and `DELETE`.
7
7
8
+
## Structure of a mutation
9
+
8
10
A mutation contains the following elements:
9
11
10
12
* The keyword `mutation`
@@ -23,7 +25,7 @@ mutation myCreateCustomer{
23
25
}
24
26
```
25
27
26
-
In this example, `myCreateCustomer` identifies your implementation. `CustomerInput` is a non-nullable object that defines a customer. (The exclamation point indicates the value is non-nullable.) `CustomerOutput` defines which fields to return.
28
+
In this example, `myCreateCustomer` identifies your implementation. `CustomerInput` is a non-nullable object that defines a customer. (The exclamation point indicates the value is non-nullable.) The `CustomerOutput` object defines which fields to return.
27
29
28
30
Now let's take a look at a fully-defined mutation. This time, we'll specify the minimum fields needed as input to create a customer (`firstname`, `lastname`, `email`, and `password`). We could include the same fields in the output, but GraphQL allows you to return only the data you need, which is the customer `id`.
Specifying variables in a mutation can help increase code re-use. Consider the following steps when creating a mutation that contains one or more variables:
83
+
Specifying variables in a mutation can help increase code re-use. Consider the following requirements when generating a mutation that contains one or more variables:
82
84
83
85
* All variables must be declared up-front, immediately after the operation name.
84
86
* Variables are typed: they can be scalar or an object.
A GraphQL search query can contain the following components:
8
+
A GraphQL query retrieves data from the Magento server in a similar manner as a REST GET call. The current set of Magento GraphQL queries allow a mobile app or browser to render a wide variety of information, including the following:
9
+
10
+
* A set of products to be displayed. This can include the entire catalog or those that match customer-specified criteria.
11
+
* Customer data. With a customer token, a query can retrieve basic information about a customer as well as billing and shipping addresses, wishlists, order history, and other sensitive data.
12
+
* Shopping cart contents. GraphQL supports both guest and logged-in customer carts.
13
+
* Store configuration values, including theme and CMS settings, the currency code, and supported countries.
14
+
15
+
The Magento REST GET endpoints retrieve a wide variety of information on behalf of the merchant. Many of these endpoints are for retrieving backend information. For example, the `GET /V1/customers/search` endpoint can be used to find a subset of customers that meet certain criteria, such as those that live in a particular state or have a birthday this month. Likewise, the `GET /V1/invoices` endpoint can return all the recently-generated invoices. This type of functionality is not required for the frontend, so it is not available in GraphQL queries. The queries are designed to improve the customer's user experience by quickly retrieving the data needed to render pages.
16
+
17
+
Over time, the Magento GraphQL queries will duplicate the functionality of all storefront-facing GET calls, while making it possible to query more data in one request. The main difference will be that GraphQL will support storefront use cases, while REST will support admin use cases.
18
+
19
+
## Structure of a query
20
+
21
+
A query contains the following elements:
22
+
23
+
* The optional keyword `query`. If no keyword is specified at the beginning of a request, the processor assumes the request is a query.
24
+
* An operation name for your local implementation. This name is required if you include variables. Otherwise, it is optional.
25
+
* The query name
26
+
* The terms to search for. The terms can be in the form of objects, attributes, or a combination. Queries that don't require search terms obtain their context from the customer's authorization token or store ID, both of which are specified in the header of the call.
27
+
* The output object, which specifies which data the query returns.
28
+
29
+
The following example shows the structure of the `cart` query:
30
+
31
+
```text
32
+
query myCartQuery{
33
+
cart(cart_id: String!): Cart
34
+
}
35
+
```
36
+
37
+
In the preceding example, `myCartQuery` identifies your implementation of the `cart` query. `cart_id` is a non-nullable string that defines the cart to query. (The exclamation point indicates the value is non-nullable.) The `Cart` output object defines which fields to return.
In this example, we've supplied a cart ID as input, (which was generated by the `createEmptyCart` mutation). The output includes the `cart_id` as well as selected information about the items in the cart and the billing and shipping addresses.
64
+
65
+
The following example shows the query response:
66
+
67
+
```json
68
+
{
69
+
"data": {
70
+
"cart": {
71
+
"cart_id": "1WxKm8WUm3uFKXLlHXezew5WREfVRPAn",
72
+
"items": [
73
+
{
74
+
"id": "5",
75
+
"qty": 1
76
+
}
77
+
],
78
+
"billing_address": {
79
+
"firstname": "Veronica",
80
+
"lastname": "Costello",
81
+
"postcode": "49628-7978"
82
+
},
83
+
"shipping_addresses": [
84
+
{
85
+
"firstname": "Veronica",
86
+
"lastname": "Costello",
87
+
"postcode": "49628-7978"
88
+
}
89
+
]
90
+
}
91
+
}
92
+
}
93
+
```
94
+
95
+
{:.bs-callout .bs-callout-tip}
96
+
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.
97
+
98
+
## Query variables
99
+
100
+
Specifying variables in a query can help increase code re-use. Consider the following requirements when generating a query that contains one or more variables:
101
+
102
+
* All variables must be declared up-front, immediately after the operation name.
103
+
* Variables are typed: they can be scalar or an object.
104
+
* You must use all declared variables. Object variables are defined in JSON.
105
+
106
+
The following example declares the `$cart_id` variable. It is referenced in the `input` statement.
A product search query can contain the following components:
7
141
8
142
* A full text search keyword
9
143
* Filters (search criteria)
10
144
* Pagination information
11
145
* Sorting instructions
12
146
13
-
## Specifying full text search keywords
147
+
###Specifying full text search keywords
14
148
15
149
The `search` element causes Magento to perform a full text search on the specified keywords. (This is the same type of search that is performed from the storefront. If multiple keywords are specified, each keyword is evaluated separately.)
16
150
17
151
The `search` element is optional, but it can be used with or without filters. Each query must contain a `search` or `filter` element.
18
152
19
-
## Specifying filters
153
+
###Specifying filters
20
154
21
155
The `filter` element defines which search criteria to use to find the desired results. As with a REST call, each filter defines the field to be searched, the condition type, and the search value.
22
156
23
157
Search filters are logically ANDed unless an `or` statement is specified. The search query can contain unlimited number of nested `or` clauses. However, you cannot perform a logical `or` across two AND clauses, such as (A AND B) OR (X AND Y).
24
158
25
-
### Search fields
159
+
####Search fields
26
160
27
161
Each object type defines which fields can be searched. See the object-specific documentation for details.
28
162
29
163
{:.bs-callout .bs-callout-info}
30
164
You cannot specify the same search field twice in a GraphQL query.
31
165
32
-
### Condition types and search values
166
+
####Condition types and search values
33
167
34
168
The following table lists available condition types and provides the SQL statement equivalents.
`to` and `from` must always be used together. These condition types can be used in the same search term. For example, `qty: {from: "10" to: "20"}`.
55
189
56
190
`gt` and `lt` can be used in the same search term. For example, `qty: {gt: "10" lt: "20"}`.
57
191
58
-
## Specifying pagination
192
+
###Specifying pagination
59
193
60
194
Magento's GraphQL implementation of pagination uses offsets so that it operates in the same manner as REST and SOAP API requests.
61
195
62
-
The `pageSize` attribute specifies the maximum number of items to return. If no value is specified, 20 items are returned.
196
+
The `pageSize` attribute specifies the maximum number of items to return. If no value is specified, 20 items are returned.
63
197
64
198
The `currentPage` attribute specifies which page of results to return. If no value is specified, the first page is returned. If you specify a value that is greater than the number of available pages, an error is returned.
65
199
66
200
You can include the `total_pages` attribute in the `page_info` section of the output definition to indicate how many pages were returned for the query.
67
201
68
-
## Sorting instructions
202
+
###Sorting instructions
69
203
70
204
The `sort` object allows you to specify which field or fields to use for sorting the results. If you specify more than one field, Magento sorts by the first field listed. Then, if any items have the same value, those items will be sorted by the secondary field. The value for each field can be set to either `ASC` or `DESC`.
71
205
@@ -78,11 +212,11 @@ sort: {
78
212
}
79
213
```
80
214
81
-
## Example Searches
215
+
###Example Product Searches
82
216
83
217
The following sections provide examples of each type of search. These examples use the Magento Open Source sample data.
84
218
85
-
### Full text search
219
+
####Full text search
86
220
87
221
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.
88
222
@@ -116,7 +250,7 @@ The following search returns items that contain the word `yoga` or `pants`. The
116
250
117
251
The search returns 45 items.
118
252
119
-
### Full text search with filters
253
+
####Full text search with filters
120
254
121
255
The following sample query returns a list of products that meets the following criteria:
122
256
@@ -212,7 +346,7 @@ The query returns the following:
212
346
}
213
347
```
214
348
215
-
### Simple search using a timestamp
349
+
####Simple search using a timestamp
216
350
217
351
The following search finds all products that were added after the specified time (midnight, November 1, 2017).
218
352
@@ -251,7 +385,7 @@ The following search finds all products that were added after the specified time
251
385
}
252
386
```
253
387
254
-
### Simple Logical OR search
388
+
####Simple Logical OR search
255
389
256
390
The following example searches for all products whose `sku` begins with the string `24-MB` or whose `name` ends with `Bag`.
257
391
@@ -297,7 +431,7 @@ The following example searches for all products whose `sku` begins with the stri
297
431
298
432
The query returns 8 items.
299
433
300
-
### Logical AND and OR search
434
+
####Logical AND and OR search
301
435
302
436
This query searches for products that have `name` that ends with `Orange` or has a `sku` that indicates the product is a pair of women’s shorts in size 29 (`WSH%29%`). The system performs a logical AND to restrict the results to those that cost from $40 to $49.99.
303
437
@@ -343,4 +477,4 @@ This query searches for products that have `name` that ends with `Orange` or has
Copy file name to clipboardExpand all lines: guides/v2.3/graphql/reference/products.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ Each query attribute is defined below:
21
21
22
22
Attribute | Description
23
23
--- | ---
24
-
`search` | Performs a full-text search using the specified key words. This attribute is optional. See [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html) for more information.
24
+
`search` | Performs a full-text search using the specified key words. This attribute is optional. See [Queries]({{ page.baseurl }}/graphql/queries.html) for more information.
25
25
`filter` | Identifies which attributes to search for and return. This attribute is required. See [ProductFilterInput](#ProductFilterInput) for more information.
26
-
`pageSize` | Specifies the maximum number of results to return at once. The default value is 20. See [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html) for more information.
27
-
`currentPage` | Specifies which page of results to return. The default value is 1. See [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html) for more information.
28
-
`sort` | Specifies which attribute to sort on, and whether to return the results in ascending or descending order. See [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html) for more information.
26
+
`pageSize` | Specifies the maximum number of results to return at once. The default value is 20. See [Queries]({{ page.baseurl }}/graphql/queries.html) for more information.
27
+
`currentPage` | Specifies which page of results to return. The default value is 1. See [Queries]({{ page.baseurl }}/graphql/queries.html) for more information.
28
+
`sort` | Specifies which attribute to sort on, and whether to return the results in ascending or descending order. See [Queries]({{ page.baseurl }}/graphql/queries.html) for more information.
29
29
`Products` | An output object that contains the results of the query. See [Response](#Response) for details.
30
30
{:style="table-layout:auto;"}
31
31
@@ -44,7 +44,7 @@ filter: {
44
44
}
45
45
```
46
46
47
-
See [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html) for more information about the operators.
47
+
See [Queries]({{ page.baseurl }}/graphql/queries.html) for more information about the operators.
48
48
49
49
Magento processes the attribute values specified in a `ProductFilterInput` as simple data types (strings, integers, booleans). However, returned attributes can be a different, complex, data type. For example, in a response, `price` is an object that contains a monetary value and a currency code.
50
50
@@ -378,7 +378,7 @@ Field | Type | Description
378
378
379
379
## Sample query
380
380
381
-
You can review several general interest `products` queries at [Searches and pagination in GraphQL]({{ page.baseurl }}/graphql/search-pagination.html).
381
+
You can review several general interest `products` queries at [Queries]({{ page.baseurl }}/graphql/queries.html).
382
382
383
383
The following query returns layered navigation for products that have a `sku` containing the string `24-WB`.
0 commit comments