Last active
February 16, 2024 05:10
-
-
Save leoloso/87f7ab9e142a5df1698fef1b0b6d3d1d to your computer and use it in GitHub Desktop.
GraphQL query: Import Podcast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query FetchPodcastRSSData( | |
$url: URL! | |
) | |
@configureWarningsOnExportingDuplicateVariable(enabled: false) | |
{ | |
_sendHTTPRequest(input: { url: $url, method: GET }) { | |
body @remove | |
rssJSON: _strDecodeXMLAsJSON( | |
xml: $__body | |
alwaysArrayTagNames: ["itunes:category"] | |
) | |
# Channel | |
# ---------------------------- | |
# Summary | |
channelSummary: _objectProperty( | |
object: $__rssJSON | |
by: { path: "rss.channel.itunes:summary" } | |
) @export(as: "channelSummary") | |
# Categories | |
# (These are currently not used anywhere) | |
channelCategories: _objectProperty( | |
object: $__rssJSON | |
by: { path: "rss.channel.itunes:category" } | |
) @export(as: "channelCategories") | |
# Items | |
# ---------------------------- | |
items: _objectProperty( | |
object: $__rssJSON | |
by: { path: "rss.channel.item" } | |
) @export(as: "items") | |
} | |
} | |
query CreateInputsForMutation( | |
$authorUsername: String! = "admin", | |
$categoryMappingFromNameToIDs: JSONObject! | |
) | |
@depends(on: "FetchPodcastRSSData") | |
{ | |
postInputs: _echo( | |
value: $items | |
) | |
@underEachArrayItem( | |
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 11] | |
passValueOnwardsAs: "item" | |
) | |
# Retrieve the properties from each item | |
# content | |
@applyField( | |
name: "_objectProperty" | |
arguments: { | |
object: $item, | |
by: { key: "description" } | |
} | |
passOnwardsAs: "itemDescription" | |
) | |
#title | |
@applyField( | |
name: "_objectProperty" | |
arguments: { | |
object: $item, | |
by: { key: "itunes:title" } | |
failIfNonExistingKeyOrPath: false | |
} | |
passOnwardsAs: "itemTitle" | |
) | |
# categories (set them only if provided) | |
@applyField( | |
name: "_echo" | |
arguments: { value: [] } | |
passOnwardsAs: "itemCategoryIDs" | |
) | |
@applyField( | |
name: "_propertyIsSetInJSONObject" | |
arguments: { | |
object: $item, | |
by: { key: "itunes:category" } | |
} | |
passOnwardsAs: "hasItemCategories" | |
) | |
@if( | |
condition: $hasItemCategories | |
affectDirectivesUnderPos: [1, 2, 3, 4, 5] | |
) | |
@applyField( | |
name: "_objectProperty" | |
arguments: { | |
object: $item, | |
by: { key: "itunes:category" } | |
} | |
passOnwardsAs: "itemCategoryNameObjects" | |
) | |
@applyField( | |
name: "_arrayOfJSONObjectsExtractProperty" | |
arguments: { | |
array: $itemCategoryNameObjects, | |
key: "@text" | |
} | |
passOnwardsAs: "itemCategoryNames" | |
) | |
@applyField( | |
name: "_arrayFlipToObject" | |
arguments: { | |
array: $itemCategoryNames, | |
} | |
passOnwardsAs: "itemCategoryNamesFlippedObject" | |
) | |
@applyField( | |
name: "_objectIntersectKey" | |
arguments: { | |
object: $categoryMappingFromNameToIDs, | |
objects: [$itemCategoryNamesFlippedObject], | |
} | |
passOnwardsAs: "itemCategoryIDsFlippedObject" | |
) | |
@applyField( | |
name: "_objectValues" | |
arguments: { | |
object: $itemCategoryIDsFlippedObject, | |
} | |
passOnwardsAs: "itemCategoryIDs" | |
) | |
# input for the `createPost` mutation | |
@applyField( | |
name: "_echo" | |
arguments: { | |
value: { | |
status: draft | |
authorBy: { username: $authorUsername } | |
contentAs: { html: $itemDescription } | |
excerpt: $channelSummary | |
title: $itemTitle | |
categoriesBy: { | |
ids: $itemCategoryIDs | |
} | |
} | |
} | |
setResultInResponse: true | |
) | |
@export(as: "postInputs") | |
} | |
mutation CreatePosts | |
@depends(on: "CreateInputsForMutation") | |
{ | |
createdPostIDs: _echo(value: $postInputs) | |
@underEachArrayItem( | |
passValueOnwardsAs: "postInput" | |
) | |
@applyField( | |
name: "createPost" | |
arguments: { | |
input: $postInput | |
}, | |
setResultInResponse: true | |
) | |
@export(as: "createdPostIDs") | |
} | |
query ImportPostsFromPodcastRSS | |
@depends(on: "CreatePosts") | |
{ | |
createdPosts: posts( | |
filter: { | |
ids: $createdPostIDs, | |
status: any | |
} | |
) { | |
id | |
slug | |
date | |
status | |
rawTitle | |
rawContent | |
rawExcerpt | |
author { | |
id | |
slug | |
} | |
categories { | |
id | |
name | |
} | |
} | |
} |
Author
leoloso
commented
Feb 15, 2024
Pass variables like this:
{
"url": "https://audioboom.com/channels/5100620.rss",
"categoryMappingFromNameToIDs": {
"News": 4,
"Tech News": 5,
"Technology": 16,
"Science": 27
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment