Field To Input
1 domain | 5 domains | 25 domains |
---|---|---|
$19.99 | $39.99 | $79.99 |
Buying the extension gives you a license for 1 year (renewable every year), that includes support and access to all extension updates. Prices are in USD.
🛍️ Buy “Field To Input” Extension
Retrieve the value of a field, manipulate it, and input it into another field or directive, all within the same operation.
Pass the value of field field
as input to another field via $__field
, and as input to a directive via field @passOnwards(as: "variableName")
.
$__field
permalink
Pass the field value as input to another field. The syntax to reference the field value is: $
(i.e. the symbol for a variable in GraphQL), followed by __
and the field alias or name.
For instance, the value from field excerpt
is referenced as $__excerpt
, and postTitle: title
is referenced as $__postTitle
.
The response from the second field can itself be used as input to another field:
{
posts {
excerpt
# Referencing previous field with name "excerpt"
isEmptyExcerpt: _isEmpty(value: $__excerpt)
# Referencing previous field with alias "isEmptyExcerpt"
isNotEmptyExcerpt: _not(value: $__isEmptyExcerpt)
}
}
The response will be:
{
"data": {
"posts": [
{
"excerpt": "Some post excerpt",
"isEmptyExcerpt": false,
"isNotEmptyExcerpt": true
},
{
"excerpt": "",
"isEmptyExcerpt": true,
"isNotEmptyExcerpt": false
}
]
}
}
@passOnwards
permalink
Directive @passOnwards
makes the field's resolved value available to subsequent directives via a dynamic variable.
In the query below, field notHasComments
is composed by obtaining the value from field hasComments
and calculating its opposite value. This works by:
- Making the field's value available via
@passOnwards
; the field's value can then be input into any subsequent directive @applyField
takes the input (exported under dynamic variable$postHasComments
), applies the global fieldnot
into it, and stores the result back into the field
{
posts {
id
hasComments
notHasComments: hasComments
@passOnwards(as: "postHasComments")
@applyField(
name: "_not"
arguments: {
value: $postHasComments
},
setResultInResponse: true
)
}
}
This will produce:
{
"data": {
"posts": [
{
"id": 1724,
"hasComments": true,
"notHasComments": false
},
{
"id": 358,
"hasComments": false,
"notHasComments": true
},
{
"id": 555,
"hasComments": false,
"notHasComments": true
}
]
}
}
Examples permalink
If the post's excerpt is empty, use the title instead:
{
posts {
title
originalExcerpt: excerpt
isEmptyExcerpt: _isEmpty(value: $__originalExcerpt)
excerpt: _if(condition: $__isEmptyExcerpt, then: $__title, else: $__originalExcerpt)
}
}
Retrieve data from an external REST endpoint, and manipulate its data to suit your requirements.
{
externalData: _sendJSONObjectItemHTTPRequest(input: { url: "https://example.com/rest/some-external-endpoint"} )
userName: _objectProperty(object: $__externalData, by: { path: "data.user.name" })
userLastName: _objectProperty(object: $__externalData, by: { path: "data.user.surname" })
}
This will produce:
{
"data": {
"externalData": {
"data": {
"user": {
"id": 1,
"name": "Leo",
"surname": "Loso"
}
}
},
"userName": "Leo",
"userLastName": "Loso"
}
}
Using the @remove
directive on externalData
, we can also avoid printing the external endpoint source data in the response:
{
externalData: _sendJSONObjectItemHTTPRequest(input: { url: "https://example.com/rest/some-external-endpoint" } ) @remove
userName: _objectProperty(object: $__externalData, by: { path: "data.user.name" })
userLastName: _objectProperty(object: $__externalData, by: { path: "data.user.surname" })
}
This will now produce:
{
"data": {
"userName": "Leo",
"userLastName": "Loso"
}
}
Retrieve the posts for every user that mention the user's email:
{
users {
email
posts(filter: { search: $__email }) {
id
title
}
}
}
Send a newsletter defining the to
and from
emails through the optionValue
field:
mutation {
fromEmail: optionValue(name: "admin_email")
toEmail: optionValue(name: "subscribers_email_list_recipient_address")
_sendEmail(
from: {
email: $__fromEmail
}
to: $__toEmail
subject: "Weekly summary"
messageAs: {
html: "..."
}
)
}
Execute conditional operations based on the value of the field. In this query, users "Leo"
and "Peter"
get their names converted to upper case, since they are in the "special user" array, while "Martin"
does not:
query {
users {
name
@passOnwards(as: "userName")
@applyField(
name: "_inArray"
arguments: {
value: $userName
array: ["Leo", "John", "Peter"]
}
passOnwardsAs: "isSpecialUser"
)
@if(
condition: $isSpecialUser
)
@strUpperCase
}
}
...producing:
{
"data": {
"users": [
{
"name": "LEO"
},
{
"name": "Martin"
},
{
"name": "PETER"
}
]
}
}
Bundles including extension permalink
- “All Extensions” Bundle
- “Application Glue & Automator” Bundle
- “Content Translation” Bundle
- “Public API” Bundle
Recipes using extension permalink
- Querying dynamic data
- Duplicating multiple blog posts at once
- Customizing content for different users
- Search, replace, and store again
- Adapting content in bulk
- Site migrations
- Inserting/Removing a (Gutenberg) block in bulk
- Modifying (and storing again) the image URLs from all Image blocks in a post
- Translating block content in a post to a different language
- Bulk translating block content in multiple posts to a different language
- Sending emails with pleasure
- Sending a notification when there is a new post
- Sending a daily summary of activity
- Automatically adding a mandatory block
- Interacting with external services via webhooks
- Retrieving data from an external API
- Not leaking credentials when connecting to services
- Handling errors when connecting to services
- Creating an API gateway
- Transforming data from an external API
- Pinging external services
- Updating large sets of data
- Importing a post from another WordPress site
- Distributing content from an upstream to multiple downstream sites
🛍️ Buy “Field To Input” Extension