Skip to content

bigmoves/swell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

26 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Swell

Package Version Hex Docs

A GraphQL implementation in Gleam providing query parsing, execution, and introspection support.

Note: If you're looking for a GraphQL client, check out Squall.

Swell

Features

  • Query parsing and execution
  • Mutations with input types
  • Subscriptions for real-time updates
  • Introspection support
  • Type-safe schema builder
  • Fragment support (inline and named)

Quick Start

Check out the /example directory for an example with SQLite.

Usage

import swell/schema
import swell/executor
import swell/value

// Define your schema
let user_type = schema.object_type("User", "A user", [
  schema.field("id", schema.id_type(), "User ID", fn(ctx) {
    case ctx.data {
      Some(value.Object(fields)) -> {
        case list.key_find(fields, "id") {
          Ok(id_val) -> Ok(id_val)
          Error(_) -> Ok(value.Null)
        }
      }
      _ -> Ok(value.Null)
    }
  }),
  schema.field("name", schema.string_type(), "User name", fn(ctx) {
    case ctx.data {
      Some(value.Object(fields)) -> {
        case list.key_find(fields, "name") {
          Ok(name_val) -> Ok(name_val)
          Error(_) -> Ok(value.Null)
        }
      }
      _ -> Ok(value.Null)
    }
  }),
])

let query_type = schema.object_type("Query", "Root query", [
  schema.field("user", user_type, "Get a user", fn(_ctx) {
    Ok(value.Object([
      #("id", value.String("1")),
      #("name", value.String("Alice")),
    ]))
  }),
])

let my_schema = schema.schema(query_type, None)

// Execute a query
let result = executor.execute("{ user { id name } }", my_schema, schema.context(None))

Known Limitations

  • Directives not implemented (@skip, @include, custom directives)
  • Interface types not implemented
  • Custom scalar serialization/deserialization (can define custom scalar types but no validation or coercion beyond built-in types)

Development

gleam test  # Run tests
gleam build # Build the package

About

๐ŸŒŠ A GraphQL implementation in Gleam

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages