Skip to content

A complete GraphQL client shard for the Crystal language inspired by Apollo client including error handling and planned support for caching, authentication and subscriptions.

License

Notifications You must be signed in to change notification settings

itsezc/crystal-gql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

dependencies:

  crystal-gql:
    github: itsezc/crystal-gql

Then run:

shards install

Initializing

require "crystal-gql"

# Define the client
api = GraphQLClient.new "https://countries.trevorblades.com"

Querying

# 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:

api.add_header("Authorization", "Bearer: TOKEN")
# useQuery
data, error, loading = api.useQuery(GQL {
	"continents" => [
		"code",
		"name",
		{
			"countries" => [
				"name",
				"capital",
				{
					"languages" => [
						"name"
					]
				}
			]
		}
	]
})

About

A complete GraphQL client shard for the Crystal language inspired by Apollo client including error handling and planned support for caching, authentication and subscriptions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published