馃寠 A GraphQL implementation in Gleam
1# Swell 2 3[![Package Version](https://img.shields.io/hexpm/v/swell)](https://hex.pm/packages/swell) 4[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/swell/) 5 6A GraphQL implementation in Gleam providing query parsing, execution, and introspection support. 7 8> **Note:** If you're looking for a GraphQL **client**, check out [Squall](https://hexdocs.pm/squall). 9 10![Swell](https://images.unsplash.com/photo-1616645728806-838c6bf184af?ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&q=80&w=2340) 11 12## Features 13 14- Query parsing and execution 15- Mutations with input types 16- Subscriptions for real-time updates 17- Introspection support 18- Type-safe schema builder 19- Fragment support (inline and named) 20 21## Quick Start 22 23Check out the `/example` directory for an example with SQLite. 24 25## Usage 26 27```gleam 28import swell/schema 29import swell/executor 30import swell/value 31 32// Define your schema 33let user_type = schema.object_type("User", "A user", [ 34 schema.field("id", schema.id_type(), "User ID", fn(ctx) { 35 case ctx.data { 36 Some(value.Object(fields)) -> { 37 case list.key_find(fields, "id") { 38 Ok(id_val) -> Ok(id_val) 39 Error(_) -> Ok(value.Null) 40 } 41 } 42 _ -> Ok(value.Null) 43 } 44 }), 45 schema.field("name", schema.string_type(), "User name", fn(ctx) { 46 case ctx.data { 47 Some(value.Object(fields)) -> { 48 case list.key_find(fields, "name") { 49 Ok(name_val) -> Ok(name_val) 50 Error(_) -> Ok(value.Null) 51 } 52 } 53 _ -> Ok(value.Null) 54 } 55 }), 56]) 57 58let query_type = schema.object_type("Query", "Root query", [ 59 schema.field("user", user_type, "Get a user", fn(_ctx) { 60 Ok(value.Object([ 61 #("id", value.String("1")), 62 #("name", value.String("Alice")), 63 ])) 64 }), 65]) 66 67let my_schema = schema.schema(query_type, None) 68 69// Execute a query 70let result = executor.execute("{ user { id name } }", my_schema, schema.context(None)) 71``` 72 73## Known Limitations 74 75- Directives not implemented (`@skip`, `@include`, custom directives) 76- Interface types not implemented 77- Custom scalar serialization/deserialization (can define custom scalar types but no validation or coercion beyond built-in types) 78 79## Development 80 81```sh 82gleam test # Run tests 83gleam build # Build the package 84```