mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-16 01:07:57 +00:00
README update.
This commit is contained in:
@@ -1,8 +1,16 @@
|
|||||||
# Simple GraphQL client
|
# Simple GraphQL client
|
||||||
|
|
||||||
[](https://github.com/lukaszraczylo/simple-gql-client/actions/workflows/test.yaml) [](https://codecov.io/gh/lukaszraczylo/simple-gql-client)
|
[](https://github.com/lukaszraczylo/simple-gql-client/actions/workflows/test.yaml) [](https://codecov.io/gh/lukaszraczylo/simple-gql-client) [](https://pkg.go.dev/github.com/lukaszraczylo/simple-gql-client)
|
||||||
|
|
||||||
It's Hasura friendly.
|
Ps. It's Hasura friendly.
|
||||||
|
|
||||||
|
- [Simple GraphQL client](#simple-graphql-client)
|
||||||
|
- [Reasoning](#reasoning)
|
||||||
|
- [Features](#features)
|
||||||
|
- [Usage example](#usage-example)
|
||||||
|
- [Setting GraphQL endpoint](#setting-graphql-endpoint)
|
||||||
|
- [Example reader code](#example-reader-code)
|
||||||
|
- [Working with results](#working-with-results)
|
||||||
|
|
||||||
## Reasoning
|
## Reasoning
|
||||||
|
|
||||||
@@ -19,30 +27,48 @@ Therefore, I present you the simple client to which you can copy & paste your gr
|
|||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
|
### Setting GraphQL endpoint
|
||||||
|
|
||||||
|
You can set the endpoint variable within your code
|
||||||
|
|
||||||
|
```go
|
||||||
|
gql.GraphQLUrl = "http://127.0.0.1:9090/v1/graphql"
|
||||||
|
```
|
||||||
|
|
||||||
|
or as an environment variable `GRAPHQL_ENDPOINT=http://127.0.0.1:9090/v1/graphql`
|
||||||
|
|
||||||
|
### Example reader code
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
fmt
|
fmt
|
||||||
gql "github.com/lukaszraczylo/simple-gql-client"
|
gql "github.com/lukaszraczylo/simple-gql-client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// (...)
|
|
||||||
|
|
||||||
gql.GraphQLUrl = "http://127.0.0.1:9090/v1/graphql"
|
|
||||||
|
|
||||||
headers := map[string]interface{}{
|
headers := map[string]interface{}{
|
||||||
"x-hasura-user-id": 37,
|
"x-hasura-user-id": 37,
|
||||||
"x-hasura-user-uuid": "bde3262e-b42e-4151-ac10-d43fb38f44a5",
|
"x-hasura-user-uuid": "bde3262e-b42e-4151-ac10-d43f0bef44a5",
|
||||||
}
|
}
|
||||||
|
|
||||||
variables := map[string]interface{}{
|
variables := map[string]interface{}{
|
||||||
"UserID": 37,
|
"fileHash": "123deadc0w321",
|
||||||
"GroupID": 11007,
|
|
||||||
}
|
}
|
||||||
var query = `query checkifUserIsAdmin($UserID: bigint, $GroupID: bigint) {
|
var query = `query searchFileKnown($fileHash: String) {
|
||||||
tbl_user_group_admins(where: {is_admin: {_eq: "1"}, user_id: {_eq: $UserID}, group_id: {_eq: $GroupID}}) {
|
tbl_file_scans(where: {file_hash: {_eq: $fileHash}}) {
|
||||||
id
|
porn
|
||||||
is_admin
|
racy
|
||||||
|
violence
|
||||||
|
virus
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
result, err := Query(query, variables, nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Query error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(result)
|
||||||
|
`
|
||||||
result := Query(query, variables, headers)
|
result := Query(query, variables, headers)
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user