Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions components/slab/actions/get-posts/get-posts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import slab from "../../slab.app.mjs";

export default {
key: "slab-get-posts",
name: "Get Posts",
description: "Get posts by ID. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.posts)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
slab,
postIds: {
type: "string[]",
label: "Post IDs",
description: "Select one or more posts to retrieve",
options: async function({ prevContext }) {
return this.slab.listPostsForOptions({
cursor: prevContext?.cursor,
});
},
},
},
async run({ $ }) {
const query = `
query GetPosts($ids: [ID!]!) {
posts(ids: $ids) {
id
title
linkAccess
archivedAt
publishedAt
insertedAt
updatedAt
version
content
banner {
original
thumb
preset
}
owner {
id
name
email
}
topics {
id
name
}
}
}
`;
const variables = {
ids: this.postIds,
};
const response = await this.slab._makeRequest({
$,
data: {
query,
variables,
},
});
const posts = response.posts || [];
$.export("$summary", `Successfully retrieved ${posts.length} post(s)`);
return posts;
},
};

124 changes: 124 additions & 0 deletions components/slab/actions/list-posts/list-posts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import slab from "../../slab.app.mjs";

export default {
key: "slab-list-posts",
name: "List Posts",
description: "List posts in the organization. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
slab,
first: {
propDefinition: [
slab,
"first",
],
},
after: {
propDefinition: [
slab,
"after",
],
},
last: {
propDefinition: [
slab,
"last",
],
},
before: {
propDefinition: [
slab,
"before",
],
},
},
async run({ $ }) {
const query = `
query ListPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) {
search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) {
edges {
node {
... on PostSearchResult {
title
highlight
content
post {
id
title
linkAccess
archivedAt
publishedAt
insertedAt
updatedAt
version
content
banner {
original
thumb
preset
}
owner {
id
name
email
}
topics {
id
name
}
}
}
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
`;
const variables = {
query: "",
...(this.first && {
first: parseInt(this.first),
}),
...(this.after && {
after: this.after,
}),
...(this.last && {
last: parseInt(this.last),
}),
...(this.before && {
before: this.before,
}),
};
const response = await this.slab._makeRequest({
$,
data: {
query,
variables,
},
});
const edges = response.search?.edges || [];
const posts = edges
.map((edge) => edge.node?.post)
.filter(Boolean);
const pageInfo = response.search?.pageInfo || {};
$.export("$summary", `Successfully retrieved ${posts.length} post(s)`);
return {
posts,
pageInfo,
edges,
};
},
};

129 changes: 129 additions & 0 deletions components/slab/actions/search-posts/search-posts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import slab from "../../slab.app.mjs";

export default {
key: "slab-search-posts",
name: "Search Posts",
description: "Search for posts based on query. See [documentation](https://studio.apollographql.com/public/Slab/variant/current/home), [schema link](https://studio.apollographql.com/public/Slab/variant/current/explorer?searchQuery=RootQueryType.search)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
slab,
query: {
type: "string",
label: "Query",
description: "Search query string",
},
first: {
propDefinition: [
slab,
"first",
],
},
after: {
propDefinition: [
slab,
"after",
],
},
last: {
propDefinition: [
slab,
"last",
],
},
before: {
propDefinition: [
slab,
"before",
],
},
},
async run({ $ }) {
const query = `
query SearchPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) {
search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) {
edges {
node {
... on PostSearchResult {
title
highlight
content
post {
id
title
linkAccess
archivedAt
publishedAt
insertedAt
updatedAt
version
content
banner {
original
thumb
preset
}
owner {
id
name
email
}
topics {
id
name
}
}
}
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
`;
const variables = {
query: this.query,
...(this.first && {
first: parseInt(this.first),
}),
...(this.after && {
after: this.after,
}),
...(this.last && {
last: parseInt(this.last),
}),
...(this.before && {
before: this.before,
}),
};
const response = await this.slab._makeRequest({
$,
data: {
query,
variables,
},
});
const edges = response.search?.edges || [];
const posts = edges
.map((edge) => edge.node?.post)
.filter(Boolean);
const pageInfo = response.search?.pageInfo || {};
$.export("$summary", `Successfully found ${posts.length} post(s) matching "${this.query}"`);
return {
posts,
pageInfo,
edges,
};
},
};

7 changes: 5 additions & 2 deletions components/slab/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/slab",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Slab Components",
"main": "slab.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
Loading
Loading