From acce6476694ba2b81a4712ab76c9d2a255f2815d Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sat, 27 Mar 2021 08:54:15 +0000 Subject: [PATCH] Update README with simple example. --- .github/workflows/test.yaml | 2 ++ README.md | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c63cda2..5c09165 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,6 +2,8 @@ name: Test and release on: push: + paths-ignore: + - '**.md' branches: - "*" diff --git a/README.md b/README.md index 4b4d487..cb0a5b3 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,25 @@ I've tried to run few graphQL clients with hasura, all of them required conversi the appropriate structures, causing issues with non-existing types ( thanks to Hasura ), for example `bigint` which was difficult to export. Therefore, I present you the simple client to which you can copy & paste your graphQL query, variables and you are good to go. -## Usage +## Features + +* Executing GraphQL queries as they are, without types declaration +* Compressing produced queries +* Support for additional headers +* Support for gzip compression ( built into Hasura ) + +## Usage example ```go +import ( + fmt + gql "github.com/lukaszraczylo/simple-gql-client" +) + +// (...) + +gql.GraphQLUrl = "http://127.0.0.1:9090/v1/graphql" + headers := map[string]interface{}{ "x-hasura-user-id": 37, "x-hasura-user-uuid": "bde3262e-b42e-4151-ac10-d43fb38f44a5", @@ -35,4 +51,15 @@ fmt.Println(result) ```json {"tbl_user_group_admins":[{"id":109,"is_admin":1}]} +``` + +## Working with results + +I'm using an amazing library [tidwall/gjson](https://github.com/tidwall/gjson) to parse the results and extract information required in further steps and I strongly recommend this approach as the easiest and close to painless. + +```go +result = gjson.Get(result, "tbl_user_group_admins.0.is_admin").Bool() +if result { + fmt.Println("User is an admin") +} ``` \ No newline at end of file