Getting started

Meta: keep this page small. The promise is "running code in 5 minutes." Anything that risks shaving 30 seconds off should be moved out. Show one Dagger example and one plain-GraphQL example so readers see the dual nature early.

Install

Hello, world

pub message(who: String!): String! {
  `hello, ${who}`
}

print(message("world"))

No install needed to get a feel for it — this REPL runs Dang in your browser. State carries across entries, so define something and use it on the next line:

let greeting = "world"

Note: the browser REPL runs the core language only — no GraphQL imports, so GitHub, Dagger, and friends aren't available here. Install the CLI for those.

A first GraphQL call

Dang is designed for GraphQL APIs. To configure them, add a dang.toml:

[imports.GitHub]
endpoint = "https://api.github.com/graphql"
authorization = "Bearer ${GITHUB_TOKEN}"

Now you can run dang in REPL mode and explore the GitHub API:

$ export GITHUB_TOKEN="$(gh auth token)"
$ dang
Welcome to Dang REPL v0.1.0
Imports: GitHub, Dagger

Type :help for commands, Tab for completion, Alt+Enter for multiline, Ctrl+D to exit

dang> GitHub.user("vito").databaseId
=> 1880

Tip: To start an interactive schema browser, try :doc.

For a more elaborate GitHub demo, check out demos/github/main.dang.

A Dagger module in 10 lines

Dang is a natural fit for writing and consuming Dagger modules.

TODO: update this for Dagger 1.0

$ dagger init --sdk=dang
type Greeter {
  pub message(target: String!): String! {
    container
      .from("ubuntu")
      .withExec(["apt-get", "update", "-y"])
      .withExec(["apt-get", "install", "-y", "cowsay"])
      .withExec(["/usr/games/cowsay", `Hello, ${target}!`])
      .stdout
  }
}

Where next