Skip to content

Commit

Permalink
Fix README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieupost committed May 4, 2021
1 parent 6272a0b commit abea2fb
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
GraphQL client for Go.

* Simple, familiar API
* Respects `context.Context` timeouts and cancellation
* Pass context.Context to the http client
* Build and execute a GraphQL request using json or multipart
* Use strong Go types for response data
* Use variables, custom headers and a custom http client
Expand All @@ -21,55 +21,55 @@ $ go get github.com/weavedev/go-gqlclient

```go
import (
gql "github.com/weavedev/go-gqlclient"
gql "github.com/weavedev/go-gqlclient"
)


// Create a client (safe to share across requests)
client := gql.NewClient(
"https://localhost/graphql",
// Optionally supply options:
// Set default headers.
gql.WithDefaultHeader("Authorization", "Bearer " + token),
// Use a custom http.Client.
gql.WithHTTPClient(customClient),
// Use another request builder (default: gql.JSONRequestBuilder).
gql.WithRequestBuilder(gql.MultipartRequestBuilder),
"https://localhost/graphql",
// Optionally supply options:
// Set default headers.
gql.WithDefaultHeader("Authorization", "Bearer " + token),
// Use a custom http.Client.
gql.WithHTTPClient(customClient),
// Use another request builder (default: gql.JSONRequestBuilder).
gql.WithRequestBuilder(gql.MultipartRequestBuilder),
)

// Make a request
req := gql.NewRequest(`
query ($key: String!) {
item(id: $key) {
field1
field2
field3
}
}`,
// Optionally supply options:
// Set any variables.
gql.WithVar("key", "value"),
// Set header fields.
gql.WithHeader("Cache-Control", "no-cache"),
// Pass a Context for the request (default: context.Background()).
gql.WithContext(ctx),
query ($key: String!) {
item(id: $key) {
field1
field2
field3
}
}`,
// Optionally supply options:
// Set any variables.
gql.WithVar("key", "value"),
// Set header fields.
gql.WithHeader("Cache-Control", "no-cache"),
// Pass a Context for the request (default: context.Background()).
gql.WithContext(ctx),
)

// Do the request and capture the response.
var resp struct {
Item struct {
Field1 string
Field2 string
Field3 string
}
Item struct {
Field1 string
Field2 string
Field3 string
}
}
err := client.Do(req, &resp)

// Inspect the returned GraphQL errors
var gqlerrs gql.ErrorList
if errors.As(err, &gqlerrs) {
// Check path
println(gqlerrs[0].Path)
// Check path
println(gqlerrs[0].Path)
}
```

Expand Down

0 comments on commit abea2fb

Please sign in to comment.