⭐️ Released v2.4 with Application Passwords support, compatibility with WordPress multisite, and mutations for pages
Gato GraphQL v2.4
has been released with several improvements and bug fixes.
Application Passwords Support
It is now possible to use WordPress Application Passwords to send an authenticated request to the GraphQL endpoint.
For instance, we can pass the application password when executing the curl
command against the GraphQL server, replacing the USERNAME
and PASSWORD
values:
curl -i \
--user "USERNAME:PASSWORD" \
-X POST \
-H "Content-Type: application/json" \
-d '{"query": "{ me { name } }"}' \
https://mysite.com/graphql
When using Gato GraphQL PRO, thanks to the newly added _strBase64Encode
field, we can use GraphQL to execute authenticated HTTP requests against another WordPress site.
The query below receives the username and application password (and the endpoint to connect to), creates the required authentication header (of type "Basic base64encoded(username:password)"), and sends an HTTP request against the GraphQL server, passing the GraphQL query to execute:
query GetDataFromExternalWPSite(
$username: String!
$appPassword: String!
$endpoint: URL!
) {
loginCredentials: _sprintf(
string: "%s:%s",
values: [$username, $appPassword]
)
@remove
base64EncodedLoginCredentials: _strBase64Encode(
string: $__loginCredentials
)
@remove
loginCredentialsHeaderValue: _sprintf(
string: "Basic %s",
values: [$__base64EncodedLoginCredentials]
)
@remove
externalHTTPRequestWithUserPassword: _sendGraphQLHTTPRequest(input:{
endpoint: $endpoint,
query: """
{
me {
name
}
}
""",
options: {
headers: [
{
name: "Authorization",
value: $__loginCredentialsHeaderValue
}
]
}
})
}
Compatibility with WordPress Multisite
Several issues were fixed to make Gato GraphQL be compatible with a WordPress Multisite network.
It is now possible to activate a single license of Gato GraphQL PRO to operate the whole multisite.
Check the video for demo Translating pages on a Multilingual site based on WordPress Multisite, where Gato GraphQL helps translate all pages in a multilingual site based on a WordPress Multisite network:
Added page mutations to the GraphQL schema
Added the following mutations to the GraphQL schema:
Root.createPage
Root.updatePage
Page.update
For instance, you can now execute this GraphQL query to modify a page:
mutation UpdatePage {
updatePage(input: {
id: 2
title: "Updated title"
contentAs: { html: "Updated content" },
status: pending
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
page {
id
rawTitle
rawContent
status
}
}
}
Added fields to fetch the logged-in user's pages
v2.4
also adds fields to retrieve the logged-in user's pages.
The previously-existing fields Root.page
, Root.pages
and Root.pageCount
retrieve pages for any user, but only public ones (i.e. those with status "publish"
).
From this version on, we can fetch public or private pages from the logged-in user (i.e. with status "publish"
, "pending"
, "draft"
or "trash"
), using these new fields:
Root.myPage
Root.myPages
Root.myPageCount
query {
myPages(filter: { status: [draft, pending] }) {
id
title
status
}
}
Added fields to fetch the site's locale and language
Added the following fields to the GraphQL schema:
Root.siteLocale
Root.siteLanguage
For instance, executing the following query:
{
siteLocale
siteLanguage
}
...might produce:
{
"data": {
"siteLocale": "en_US",
"siteLanguage": "en"
}
}
These fields are provided via the new "Site" module. Disabling this module will remove the fields from the GraphQL schema.
Improvements and fixes
- Install "internal" private custom endpoint (#2684)
- Added documentation for new PRO field
_strBase64Encode
(#2673) - Link extensions to the Extensions Reference in gatographql.com (#2675)
- Added YouTube channel link to About page (#2676)
- Added predefined persisted queries:
- Highlight extensions and enable link to visit in website (#2674)
- GraphiQL client (for LocalWP) now uses site URL as endpoint (#2686)
- Internal server error from passing string when expected int (v2.4.1)