home / skills / windmill-labs / windmill / write-script-graphql

This skill helps you write GraphQL queries and mutations accurately by guiding structure, variables, and binding with your scripts.

npx playbooks add skill windmill-labs/windmill --skill write-script-graphql

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
984 B
---
name: write-script-graphql
description: MUST use when writing GraphQL queries.
---

## CLI Commands

Place scripts in a folder. After writing, run:
- `wmill script generate-metadata` - Generate .script.yaml and .lock files
- `wmill sync push` - Deploy to Windmill

Use `wmill resource-type list --schema` to discover available resource types.

# GraphQL

## Structure

Write GraphQL queries or mutations. Arguments can be added as query parameters:

```graphql
query GetUser($id: ID!) {
  user(id: $id) {
    id
    name
    email
  }
}
```

## Variables

Variables are passed as script arguments and automatically bound to the query:

```graphql
query SearchProducts($query: String!, $limit: Int = 10) {
  products(search: $query, first: $limit) {
    edges {
      node {
        id
        name
        price
      }
    }
  }
}
```

## Mutations

```graphql
mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    id
    name
    createdAt
  }
}
```

Overview

This skill helps you write and integrate GraphQL queries and mutations into scripts for a workflow platform. It focuses on correct operation structure, variable binding from script arguments, and the deployment steps required to make GraphQL-backed scripts runnable and self-hostable.

How this skill works

You author GraphQL queries or mutations in script files and declare variables as operation parameters. The script runner automatically binds script arguments to GraphQL variables, so inputs flow directly into queries and mutations. After writing, generate metadata and lock files with a CLI command and push the script to deploy it to the platform.

When to use it

  • When a script needs to fetch structured data via GraphQL queries.
  • When a script must perform create/update operations using GraphQL mutations.
  • When you want to pass runtime inputs into GraphQL using script arguments.
  • When integrating GraphQL endpoints into webhooks, workflows, or UIs.
  • When preparing scripts for deployment and orchestration on the platform.

Best practices

  • Name operations (query/mutation) clearly to aid debugging and logging.
  • Use GraphQL variables instead of interpolating values to keep queries safe and reusable.
  • Provide sensible default values for variables where applicable to simplify calls.
  • Run `wmill script generate-metadata` after changes to update .script.yaml and lock files.
  • Use `wmill resource-type list --schema` to discover and match available resource types before coding.

Example use cases

  • Query a user by ID: define GetUser($id: ID!) to fetch id, name, email.
  • Search products with pagination: use variables for search string and limit/defaults.
  • Create a record via mutation: pass an input object into CreateUser mutation and return created fields.
  • Wire a GraphQL query into a webhook to return dynamic responses based on request args.
  • Embed queries into UI components or workflows to power low-code interfaces.

FAQ

How are GraphQL variables passed to the script?

Variables are passed as script arguments; the platform automatically binds those arguments to the GraphQL operation parameters.

How do I deploy a GraphQL-backed script?

After writing the script, run `wmill script generate-metadata` to create metadata and lock files, then `wmill sync push` to deploy to the platform.