Skip to content

Commit 3578c9b

Browse files
authored
docs: update scalar tag documentation (hasura#25)
* update README for scalar tag
1 parent bcf23de commit 3578c9b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Unit tests
22

3-
on: ["push", "pull_request"]
3+
on: ["push"]
44

55
jobs:
66
test-go:

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For more information, see package [`github.com/shurcooL/githubv4`](https://githu
1919
- [Authentication](#authentication)
2020
- [Simple Query](#simple-query)
2121
- [Arguments and Variables](#arguments-and-variables)
22+
- [Custom scalar tag](#custom-scalar-tag)
2223
- [Inline Fragments](#inline-fragments)
2324
- [Mutations](#mutations)
2425
- [Mutations Without Fields](#mutations-without-fields)
@@ -32,6 +33,7 @@ For more information, see package [`github.com/shurcooL/githubv4`](https://githu
3233
- [Options](#options-1)
3334
- [With operation name (deprecated)](#with-operation-name-deprecated)
3435
- [Raw bytes response](#raw-bytes-response)
36+
- [Multiple mutations with ordered map](#multiple-mutations-with-ordered-map)
3537
- [Directories](#directories)
3638
- [References](#references)
3739
- [License](#license)
@@ -176,6 +178,43 @@ if err != nil {
176178
}
177179
```
178180
181+
### Custom scalar tag
182+
183+
Because the generator reflects recursively struct objects, it can't know if the struct is a custom scalar such as JSON. To avoid expansion of the field during query generation, let's add the tag `scalar:"true"` to the custom scalar. If the scalar implements the JSON decoder interface, it will be automatically decoded.
184+
185+
```Go
186+
struct {
187+
Viewer struct {
188+
ID interface{}
189+
Login string
190+
CreatedAt time.Time
191+
DatabaseID int
192+
}
193+
}
194+
195+
// Output:
196+
// {
197+
// viewer {
198+
// id
199+
// login
200+
// createdAt
201+
// databaseId
202+
// }
203+
// }
204+
205+
struct {
206+
Viewer struct {
207+
ID interface{}
208+
Login string
209+
CreatedAt time.Time
210+
DatabaseID int
211+
} `scalar:"true"`
212+
}
213+
214+
// Output
215+
// { viewer }
216+
```
217+
179218
### Inline Fragments
180219
181220
Some GraphQL queries contain inline fragments. You can use the `graphql` struct field tag to express them.

0 commit comments

Comments
 (0)