Coding with an APIInjecting multiple resources into WP-CLI
Injecting multiple resources into WP-CLI
In guide Complementing WP-CLI, we only retrieved (and injected into WP-CLI) a single user ID. Now, let's retrieve multiple user IDs while executing a single GraphQL query.
In this GraphQL query:
- We remove the
pagination
argument from the query, as to retrieve the list of all the users with Spanish locale - We use Multiple Query Execution to export a list of the user IDs, under dynamic variable
$userIDs
- We print the elements of this array with
_arrayJoin
, joining the items with a space in between, under aliasspanishLocaleUserIDs
- We execute the operation
FormatAndPrintData
The response to this query will be:
When executing the query, the dictionary in the body of the request must indicate the name of the operation to execute ("FormatAndPrintData"
):
We must also adapt the regex (due to the new alias, the space in between the IDs, and the quotes around this string):
Printing the contents of variable SPANISH_LOCALE_USER_IDS
, we get all the IDs, separated with a space:
We can now inject all IDs together to the WP-CLI command (if it supports it), or iterate them and execute the command for each of them: