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
2.**A `POST` request with an `application/json` content type** and the GraphQL query defined by a `query` key:
135
135
```bash
136
136
curl \
137
137
-H "Content-Type: application/json" \
138
138
-d '{"query":"{ping}"}' \
139
-
http://my-project.tld/api
139
+
https://my-project.ddev.site/api
140
140
```
141
141
3.**A `POST` request with an `application/graphql` content type** and the GraphQL query defined by the raw request body:
142
142
```bash
143
143
curl \
144
144
-H "Content-Type: application/graphql" \
145
145
-d '{ping}' \
146
-
http://my-project.tld/api
146
+
https://my-project.ddev.site/api
147
147
```
148
148
149
149
#### Specifying Variables
150
150
151
-
If you need to specify any [variables](https://graphql.org/learn/queries/#variables) along with your query, then you must send request as a `POST` request with an `application/json` content type, and include a `variables` key in the JSON body alongside `query`.
151
+
If you need to specify any [variables](https://graphql.org/learn/queries/#variables) along with your query, then you must send request as a `POST` request with an `application/json` content type, and include a `variables` key in the JSON body alongside your `query`.
152
152
153
153
```bash
154
154
curl \
@@ -157,28 +157,28 @@ curl \
157
157
"query": "query($id:[Int]) { entries(id: $id) { id, title } }",
158
158
"variables": { "id": [1, 2, 3] }
159
159
}' \
160
-
http://my-project.tld/api
160
+
https://my-project.ddev.site/api
161
161
```
162
162
163
163
#### Querying a Private Schema
164
164
165
-
The Public Schema is used by default. To query against a different [schema](#define-your-schemas), pass its Access Token using an`Authorization` header.
165
+
The **Public Schema** is used by default. To query against a different [schema](#define-your-schemas), pass a valid [token](#generate-tokens) under the`Authorization` header.
If you’re unable to query a private schema because of a “missing authorization header”, make sure Craft received it from the web server with a quick post to a test template:
176
+
If you’re unable to query a private schema because of a “missing authorization header,” make sure Craft received it from the web server with a quick post to a test template:
Apache strips `Authorization` headers by default, which can be fixed by enabling [CGIPassAuth](https://httpd.apache.org/docs/2.4/en/mod/core.html#cgipassauth) or adding the following to your `.htaccess` file:
@@ -204,7 +204,7 @@ Here’s what a [query](#query-reference) for two news entries might look like,
Query results are cached by default to speed up subsequent queries, and you can disable that caching with the <config5:enableGraphQlCaching> setting.
304
+
Query results are cached by default to speed up subsequent queries, but you can disable that caching with the <config5:enableGraphQlCaching> setting.
305
305
306
-
The entire GraphQL cache is purged for any schema changes, otherwise Craft only purges caches based on content changes relevant to a given query. The more specific your query, the less likely its cache will be cleared when an entry is saved or deleted. For example:
306
+
The entire GraphQL cache is purged for any schema changes. Like template caches, Craft selectively purges GraphQL query results when the underlying elements’ content changes. Keep in mind that multiple GraphQL queries can be sent and executed in the same request, but responses will be cached and invalidated as a whole.
307
307
308
-
- If the query includes the `id` argument, its caches will only be cleared when that entry is saved or deleted.
309
-
- If the query includes `type` or `typeId` arguments, its caches will only be cleared when entries of the same type are saved or deleted.
310
-
- If the query includes `section` or `sectionId` arguments, its caches will only be cleared when entries in the same section are saved or deleted.
308
+
While combining queries may reduce the number of round-trips to your server, it may significantly impact the number of requests that Craft can serve from the cache. Consider splitting queries into chunks
311
309
312
-
## Interface Implementation
310
+
## Types
313
311
314
-
A defined type exists for each specific interface implementation. For example, if a “News” section has “Article” and “Editorial” entry types, in addition to the `EntryInterface` interface type, two additional types would be defined the GraphQL schema, if the token used allows it: `news_article_Entry` and `news_editorial_Entry` types.
312
+
Use the **Explorer** pane in the [GraphiQL IDE](#using-the-graphiql-ide) to browse queries and mutations, and the **Documentation** pane to get information about specific types. The specific types available for introspection and querying are determined by the current [schema](#define-your-schemas).
313
+
314
+
### Arguments
315
+
316
+
[Arguments](https://graphql.org/learn/queries/#arguments) typically correlate to element query params and are used to narrow the results of a query.
317
+
318
+
```gql{2}
319
+
query BlogPosts {
320
+
newsEntries(orderBy: "postDate DESC") {
321
+
title
322
+
summary
323
+
postDate@formatDateTime(format: "F j, Y")
324
+
}
325
+
}
326
+
```
327
+
328
+
### Inputs
329
+
330
+
[Input types](https://graphql.org/graphql-js/mutations-and-input-types/) determine the allowed (and required) params
331
+
332
+
### Elements
333
+
334
+
Each element type provides dedicated query and mutation interfaces that expose unique properties. A generic query type is provided for each element type that allows you to build queries from scratch, similar to the `craft.entries()` or `craft.assets()` APIs available in Twig:
Specific query types are available for some subsets of elements, like [sections](../reference/element-types/entries.md#sections). The _News_ section above would get a dedicated `newsEntries` query.
356
+
357
+
[Mutations](#mutations) follow a similar pattern—to create or update an entry in our _News_ section, you would use the dedicated `save_news_post_Entry` mutation:
Don’t forget to consider or disable [template caching](../twig/tags.md#cache)for requests that use `now` comparisons! You can pass a `x-craft-gql-cache: no-cache` header for GraphQL requests or set a relatively low [cache duration](config5:cacheDuration).
90
+
Me mindful of [template caching](../twig/tags.md#cache)when comparing against the current time!
0 commit comments