From b3e594fc4f68cd51726c9f4b8e2855ad8102b59e Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Fri, 3 Feb 2023 15:59:44 +0000 Subject: [PATCH] Update documentation. --- README.md | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e83ef27..1fe878c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Ps. It's Hasura friendly. - [Environment variables](#environment-variables) - [Cache](#cache) - [Example reader code](#example-reader-code) + - [Tips](#tips) - [Working with results](#working-with-results) ## Reasoning @@ -63,32 +64,39 @@ import ( graphql "github.com/lukaszraczylo/go-simple-graphql" ) -headers := map[string]interface{}{ - "x-hasura-user-id": 37, - "x-hasura-user-uuid": "bde1962e-b42e-1212-ac10-d43fa27f44a5", -} - -variables := map[string]interface{}{ - "fileHash": "123deadc0w321", -} - -query := `query searchFileKnown($fileHash: String) { - tbl_file_scans(where: {file_hash: {_eq: $fileHash}}) { - racy - violence - virus +func main() { + headers := map[string]interface{}{ + "x-hasura-user-id": 37, + "x-hasura-user-uuid": "bde1962e-b42e-1212-ac10-d43fa27f44a5", } -}` -gql := graphql.NewConnection() -result, err := gql.Query(query, variables, headers) -if err != nil { - fmt.Println("Query error", err) - return + variables := map[string]interface{}{ + "fileHash": "123deadc0w321", + } + + query := `query searchFileKnown($fileHash: String) { + tbl_file_scans(where: {file_hash: {_eq: $fileHash}}) { + racy + violence + virus + } + }` + + gql := graphql.NewConnection() + result, err := gql.Query(query, variables, headers) + if err != nil { + fmt.Println("Query error", err) + return + } + fmt.Println(result) } -fmt.Println(result) ``` +### Tips + +* Connection handler ( `gql := graphql.NewConnection()` ) should be created once and reused in the application especially if you run dozens of queries per second. It will allow you also to use cache and http2 to its full potential. + + **Result** ```json