Skip to content

Commit 85caf1b

Browse files
new slab components (#19354)
* new slab components * updated pnpm-lock * fixing lints * moved graphql queries to /common folder * addded common folder --------- Co-authored-by: Sergio Wong <Sergio Eliot Rodriguez Wong>
1 parent 535155d commit 85caf1b

File tree

7 files changed

+445
-8
lines changed

7 files changed

+445
-8
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import slab from "../../slab.app.mjs";
2+
3+
export default {
4+
key: "slab-get-posts",
5+
name: "Get Posts",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
slab,
16+
postIds: {
17+
type: "string[]",
18+
label: "Post IDs",
19+
description: "Select one or more posts to retrieve",
20+
options: async function({ prevContext }) {
21+
return this.slab.listPostsForOptions({
22+
cursor: prevContext?.cursor,
23+
});
24+
},
25+
},
26+
},
27+
async run({ $ }) {
28+
const query = `
29+
query GetPosts($ids: [ID!]!) {
30+
posts(ids: $ids) {
31+
id
32+
title
33+
linkAccess
34+
archivedAt
35+
publishedAt
36+
insertedAt
37+
updatedAt
38+
version
39+
content
40+
banner {
41+
original
42+
thumb
43+
preset
44+
}
45+
owner {
46+
id
47+
name
48+
email
49+
}
50+
topics {
51+
id
52+
name
53+
}
54+
}
55+
}
56+
`;
57+
const variables = {
58+
ids: this.postIds,
59+
};
60+
const response = await this.slab._makeRequest({
61+
$,
62+
data: {
63+
query,
64+
variables,
65+
},
66+
});
67+
const posts = response.posts || [];
68+
$.export("$summary", `Successfully retrieved ${posts.length} post(s)`);
69+
return posts;
70+
},
71+
};
72+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import slab from "../../slab.app.mjs";
2+
import { LIST_POSTS_QUERY } from "../../common/queries.mjs";
3+
4+
export default {
5+
key: "slab-list-posts",
6+
name: "List Posts",
7+
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)",
8+
version: "0.0.1",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
type: "action",
15+
props: {
16+
slab,
17+
first: {
18+
propDefinition: [
19+
slab,
20+
"first",
21+
],
22+
},
23+
after: {
24+
propDefinition: [
25+
slab,
26+
"after",
27+
],
28+
},
29+
last: {
30+
propDefinition: [
31+
slab,
32+
"last",
33+
],
34+
},
35+
before: {
36+
propDefinition: [
37+
slab,
38+
"before",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const query = LIST_POSTS_QUERY;
44+
const variables = {
45+
query: "",
46+
...(this.first && {
47+
first: parseInt(this.first),
48+
}),
49+
...(this.after && {
50+
after: this.after,
51+
}),
52+
...(this.last && {
53+
last: parseInt(this.last),
54+
}),
55+
...(this.before && {
56+
before: this.before,
57+
}),
58+
};
59+
const response = await this.slab._makeRequest({
60+
$,
61+
data: {
62+
query,
63+
variables,
64+
},
65+
});
66+
const edges = response.search?.edges || [];
67+
const posts = edges
68+
.map((edge) => edge.node?.post)
69+
.filter(Boolean);
70+
const pageInfo = response.search?.pageInfo || {};
71+
$.export("$summary", `Successfully retrieved ${posts.length} post(s)`);
72+
return {
73+
posts,
74+
pageInfo,
75+
edges,
76+
};
77+
},
78+
};
79+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import slab from "../../slab.app.mjs";
2+
import { SEARCH_POSTS_QUERY } from "../../common/queries.mjs";
3+
4+
export default {
5+
key: "slab-search-posts",
6+
name: "Search Posts",
7+
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)",
8+
version: "0.0.1",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
type: "action",
15+
props: {
16+
slab,
17+
query: {
18+
type: "string",
19+
label: "Query",
20+
description: "Search query string",
21+
},
22+
first: {
23+
propDefinition: [
24+
slab,
25+
"first",
26+
],
27+
},
28+
after: {
29+
propDefinition: [
30+
slab,
31+
"after",
32+
],
33+
},
34+
last: {
35+
propDefinition: [
36+
slab,
37+
"last",
38+
],
39+
},
40+
before: {
41+
propDefinition: [
42+
slab,
43+
"before",
44+
],
45+
},
46+
},
47+
async run({ $ }) {
48+
const query = SEARCH_POSTS_QUERY;
49+
const variables = {
50+
query: this.query,
51+
...(this.first && {
52+
first: parseInt(this.first),
53+
}),
54+
...(this.after && {
55+
after: this.after,
56+
}),
57+
...(this.last && {
58+
last: parseInt(this.last),
59+
}),
60+
...(this.before && {
61+
before: this.before,
62+
}),
63+
};
64+
const response = await this.slab._makeRequest({
65+
$,
66+
data: {
67+
query,
68+
variables,
69+
},
70+
});
71+
const edges = response.search?.edges || [];
72+
const posts = edges
73+
.map((edge) => edge.node?.post)
74+
.filter(Boolean);
75+
const pageInfo = response.search?.pageInfo || {};
76+
$.export("$summary", `Successfully found ${posts.length} post(s) matching "${this.query}"`);
77+
return {
78+
posts,
79+
pageInfo,
80+
edges,
81+
};
82+
},
83+
};
84+

components/slab/common/queries.mjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
export const SEARCH_POSTS_QUERY = `
2+
query SearchPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) {
3+
search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) {
4+
edges {
5+
node {
6+
... on PostSearchResult {
7+
title
8+
highlight
9+
content
10+
post {
11+
id
12+
title
13+
linkAccess
14+
archivedAt
15+
publishedAt
16+
insertedAt
17+
updatedAt
18+
version
19+
content
20+
banner {
21+
original
22+
thumb
23+
preset
24+
}
25+
owner {
26+
id
27+
name
28+
email
29+
}
30+
topics {
31+
id
32+
name
33+
}
34+
}
35+
}
36+
}
37+
cursor
38+
}
39+
pageInfo {
40+
hasNextPage
41+
hasPreviousPage
42+
startCursor
43+
endCursor
44+
}
45+
}
46+
}
47+
`;
48+
49+
export const LIST_POSTS_QUERY = `
50+
query ListPosts($query: String!, $first: Int, $after: String, $last: Int, $before: String) {
51+
search(query: $query, types: [POST], first: $first, after: $after, last: $last, before: $before) {
52+
edges {
53+
node {
54+
... on PostSearchResult {
55+
title
56+
highlight
57+
content
58+
post {
59+
id
60+
title
61+
linkAccess
62+
archivedAt
63+
publishedAt
64+
insertedAt
65+
updatedAt
66+
version
67+
content
68+
banner {
69+
original
70+
thumb
71+
preset
72+
}
73+
owner {
74+
id
75+
name
76+
email
77+
}
78+
topics {
79+
id
80+
name
81+
}
82+
}
83+
}
84+
}
85+
cursor
86+
}
87+
pageInfo {
88+
hasNextPage
89+
hasPreviousPage
90+
startCursor
91+
endCursor
92+
}
93+
}
94+
}
95+
`;
96+

components/slab/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/slab",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Slab Components",
55
"main": "slab.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)