Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cobbinma/gleamql
A Simple Graphql Client Written In Gleam ✨
https://github.com/cobbinma/gleamql
gleam graphql graphql-client
Last synced: 27 days ago
JSON representation
A Simple Graphql Client Written In Gleam ✨
- Host: GitHub
- URL: https://github.com/cobbinma/gleamql
- Owner: cobbinma
- Created: 2023-01-28T10:57:21.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-12T16:33:40.000Z (11 months ago)
- Last Synced: 2024-03-14T18:18:38.302Z (8 months ago)
- Topics: gleam, graphql, graphql-client
- Language: Gleam
- Homepage:
- Size: 40 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gleamql
[![Package Version](https://img.shields.io/hexpm/v/gleamql)](https://hex.pm/packages/gleamql)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleamql/)A Simple Graphql Client Written In Gleam ✨
## Usage
```gleam
import gleamql
import gleam/json.{string}
import gleam/dynamic.{field}
import gleam/option.{Some}
import gleam/hackneypub type Data {
Data(country: Country)
}pub type Country {
Country(name: String)
}const country_query = "query CountryQuery($code: ID!) {
country(code: $code) {
name
}
}"pub fn main() {
let assert Ok(Some(Data(country: Country(name: "United Kingdom")))) =
gleamql.new()
|> gleamql.set_query(country_query)
|> gleamql.set_variable("code", json.string("GB"))
|> gleamql.set_host("countries.trevorblades.com")
|> gleamql.set_path("/graphql")
|> gleamql.set_header("Content-Type", "application/json")
|> gleamql.set_decoder(dynamic.decode1(
Data,
field("country", of: dynamic.decode1(Country, field("name", of: string))),
))
|> gleamql.send(hackney.send)
}
```## Installation
If available on Hex this package can be added to your Gleam project:
```sh
gleam add gleamql
```and its documentation can be found at .