Stefan-neo
Stefan-neo8mo ago

Trying to run GraphQL script with windmill TS client throws error

Hi there, trying to run a windmill GraphQL script from another TS script via the windmill TS client but I'm encountering an issue. There's not much documentation on the TS client side so I'm unsure what the issue may be. Given my GraphQL script has the following params: api: Object (the one that is always created for GraphQL scripts), title: string, issueId: string, url: string, I am receiving the following issue when trying to call it via path from my TS script:
const graphQLResource = await wmill.getResource("f/resources/myResource")
await wmill.runScript("f/testDir/testAction", undefined, {
api: graphQLResource,
title: "Test Title",
issueId: "Test",
url: "https://www.google.com/"
}, true)
const graphQLResource = await wmill.getResource("f/resources/myResource")
await wmill.runScript("f/testDir/testAction", undefined, {
api: graphQLResource,
title: "Test Title",
issueId: "Test",
url: "https://www.google.com/"
}, true)
Error:
SyntaxError: Failed to parse JSON
at <parse> (:0)
at json (native)
at <anonymous> (/tmp/bun/node_modules/windmill-client/dist/client.js:238:5)
SyntaxError: Failed to parse JSON
at <parse> (:0)
at json (native)
at <anonymous> (/tmp/bun/node_modules/windmill-client/dist/client.js:238:5)
Edit: Same error when the args parameter is using [] instead of {}
7 Replies
rubenf
rubenf8mo ago
Hi @Stefan-neo , is the script f/testDir/testAction running successfully ? You should be able to see that in the runs page
Stefan-neo
Stefan-neoOP8mo ago
Hi @rubenf, the graphql script triggered by the parent runs successfully with this return
{
"myMutationName": {
"success": true
}
}
{
"myMutationName": {
"success": true
}
}
Minimal reproducible on the calling TS script side:
export async function main() {
const myGraphQLResource = await wmill.getResource("f/resources/myGraphQLResource")
await wmill.runScript("/f/myScript/scriptName", undefined, {
api: myGraphQLResource,
title: "Test from Script",
issueId: "testId",
url: "https://www.google.com/"
}, true)
return
export async function main() {
const myGraphQLResource = await wmill.getResource("f/resources/myGraphQLResource")
await wmill.runScript("/f/myScript/scriptName", undefined, {
api: myGraphQLResource,
title: "Test from Script",
issueId: "testId",
url: "https://www.google.com/"
}, true)
return
Error thrown on TS script (Bun) side:
SyntaxError: Failed to parse JSON
SyntaxError: Failed to parse JSON
at <parse> (:0)
at json (native)
at <anonymous> (/tmp/bun/node_modules/windmill-client/dist/client.js:238:5)
SyntaxError: Failed to parse JSON
SyntaxError: Failed to parse JSON
at <parse> (:0)
at json (native)
at <anonymous> (/tmp/bun/node_modules/windmill-client/dist/client.js:238:5)
Can reproduce this behavior for any other script I'm calling with wmill.runScript()
rubenf
rubenf8mo ago
@Stefan-neo i'm doing a release right now with a fix btw, your last arg shouldn't be true, you can leave it empty
Stefan-neo
Stefan-neoOP8mo ago
Yeah, just used it for verbose debugging Thanks a lot for looking into it! Will test later today
rubenf
rubenf8mo ago
you will need to pin windmill-client@ to the next release deployed:
// import { toWords } from "number-to-words@1"
import * as wmill from "windmill-client@1.295.2"

export async function main() {
return await wmill.runScript("u/rfiszel/endorsed_script", null, {
title: "Test from Script",
issueId: "testId",
url: "https://www.google.com/"
})
}
// import { toWords } from "number-to-words@1"
import * as wmill from "windmill-client@1.295.2"

export async function main() {
return await wmill.runScript("u/rfiszel/endorsed_script", null, {
title: "Test from Script",
issueId: "testId",
url: "https://www.google.com/"
})
}
does work now
Stefan-neo
Stefan-neoOP8mo ago
Hi @rubenf , short follow-up on a related matter. It seems there's no wmill.runFlow method, and wmill.runScript does not appear to work on flows.
rubenf
rubenf8mo ago
you can just call the webhook directly with fetch