Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itsezc/crystal-gql
A complete GraphQL client shard for the Crystal language inspired by Apollo client including error handling and planned support for caching, authentication and subscriptions.
https://github.com/itsezc/crystal-gql
crystal-gql crystal-language crystal-shard graphql
Last synced: 4 months ago
JSON representation
A complete GraphQL client shard for the Crystal language inspired by Apollo client including error handling and planned support for caching, authentication and subscriptions.
- Host: GitHub
- URL: https://github.com/itsezc/crystal-gql
- Owner: itsezc
- License: mit
- Created: 2020-03-30T07:38:45.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-06T15:00:19.000Z (almost 4 years ago)
- Last Synced: 2024-10-04T21:33:07.441Z (4 months ago)
- Topics: crystal-gql, crystal-language, crystal-shard, graphql
- Language: Crystal
- Homepage:
- Size: 25.4 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-graphql - crystal-gql - GraphQL client shard inspired by Apollo client (Libraries / Crystal Libraries)
README
# GraphQL Client for Crystal
A GraphQL client shard for the Crystal language.
- Version: 0.1.3
- Crystal Version: 0.35.1## Usage
**Installing**
Just add this to your shards.yml file:
```yml
dependencies:crystal-gql:
github: itsezc/crystal-gql```
Then run:
```bash
shards install
```**Initializing**
```ruby
require "crystal-gql"# Define the client
api = GraphQLClient.new "https://countries.trevorblades.com"
```**Querying**
```ruby
# useQuery
data, error, loading = api.useQuery(GQL {
"continents" => [
"code",
"name",
{
"countries" => [
"name",
"capital",
{
"languages" => [
"name"
]
}
]
}
]
})# or traditional queries
data, error, loading = api.query("{
continents {
code
name
countries {
name
capital
languages {
name
}
}
}
}")# Print data
print data
```**Querying**
With authentication:
```ruby
api.add_header("Authorization", "Bearer: TOKEN")
# useQuery
data, error, loading = api.useQuery(GQL {
"continents" => [
"code",
"name",
{
"countries" => [
"name",
"capital",
{
"languages" => [
"name"
]
}
]
}
]
})
```