|
7 | 7 | # by the server, not by the client, so it would reject a real @genqlient
|
8 | 8 | # directive as nonexistent.)
|
9 | 9 | #
|
10 |
| -# Directives may be applied to fields, arguments, or the entire query. |
11 |
| -# Directives on the line preceding the query apply to all relevant nodes in |
12 |
| -# the query; other directives apply to all nodes on the following line. (In |
13 |
| -# all cases it's fine for there to be other comments in between the directive |
14 |
| -# and the node(s) to which it applies.) For example, in the following query: |
| 10 | +# Directives may be applied to fields, arguments, or the entire query or named |
| 11 | +# fragment. Directives on the line preceding the query or a named fragment |
| 12 | +# apply to all relevant nodes in the query; other directives apply to all nodes |
| 13 | +# on the following line. (In all cases it's fine for there to be other |
| 14 | +# comments in between the directive and the node(s) to which it applies.) For |
| 15 | +# example, in the following query: |
15 | 16 | # # @genqlient(n: "a")
|
16 | 17 | #
|
17 | 18 | # # @genqlient(n: "b")
|
|
39 | 40 | # entire query (so "d", "e", and "f" take precedence over "b" and "c"), and
|
40 | 41 | # multiple directives on the same node ("b" and "c") must not conflict. Note
|
41 | 42 | # that directives on nodes do *not* apply to their "children", so "d" does not
|
42 |
| -# apply to the fields of MyInput, and "f" does not apply to field4. |
| 43 | +# apply to the fields of MyInput, and "f" does not apply to field4. (But |
| 44 | +# directives on operations and fragments do: both "b" and "c" apply to fields |
| 45 | +# of MyInput and to field4.) |
43 | 46 | directive genqlient(
|
44 | 47 |
|
45 |
| - # If set, this argument will be omitted if it has an empty value, defined |
46 |
| - # (the same as in encoding/json) as false, 0, a nil pointer, a nil interface |
47 |
| - # value, and any empty array, slice, map, or string. |
| 48 | + # If set to a string "MyType.myField", this entire @genqlient directive |
| 49 | + # will be treated as if it were applied to the specified field of the |
| 50 | + # specified type. It must be applied to an entire operation or fragment. |
| 51 | + # |
| 52 | + # This is especially useful for input-type options like omitempty and |
| 53 | + # pointer, which are equally meaningful on input-type fields as on arguments, |
| 54 | + # but there's no natural syntax to put them on fields. |
| 55 | + # |
| 56 | + # Note that for input types, unless the type has the "typename" option set, |
| 57 | + # all operations and fragments in the same package which use this type should |
| 58 | + # have matching directives. (This is to avoid needing to give them more |
| 59 | + # complex type-names.) This is not currently validated, but will be |
| 60 | + # validated in the future (see issue #123). |
| 61 | + # |
| 62 | + # For example, given the following query: |
| 63 | + # # @genqlient(for: "MyInput.myField", omitempty: true) |
| 64 | + # # @genqlient(for: "MyInput.myOtherField", pointer: true) |
| 65 | + # # @genqlient(for: "MyOutput.id", bind: "path/to/pkg.MyOutputID") |
| 66 | + # query MyQuery($arg: MyInput) { ... } |
| 67 | + # genqlient will generate a type |
| 68 | + # type MyInput struct { |
| 69 | + # MyField <type> `json:"myField,omitempty"` |
| 70 | + # MyOtherField *<type> `json:"myField"` |
| 71 | + # MyThirdField <type> `json:"myThirdField"` |
| 72 | + # } |
| 73 | + # and use it for the argument to MyQuery, and similarly if `MyOutput.id` is |
| 74 | + # ever requested in the response, it will be set to use the given type. |
| 75 | + for: String |
| 76 | + |
| 77 | + # If set, this argument (or input-type field, see "for") will be omitted if |
| 78 | + # it has an empty value, defined (the same as in encoding/json) as false, 0, |
| 79 | + # a nil pointer, a nil interface value, and any empty array, slice, map, or |
| 80 | + # string. |
48 | 81 | #
|
49 | 82 | # For example, given the following query:
|
50 | 83 | # # @genqlient(omitempty: true)
|
51 |
| - # query MyQuery(arg: String) { ... } |
| 84 | + # query MyQuery($arg: String) { ... } |
52 | 85 | # genqlient will generate a function
|
53 | 86 | # MyQuery(ctx context.Context, client graphql.Client, arg string) ...
|
54 | 87 | # which will pass {"arg": null} to GraphQL if arg is "", and the actual
|
@@ -161,8 +194,10 @@ directive genqlient(
|
161 | 194 | # type-name in multiple places unless they request the exact same fields, or
|
162 | 195 | # if your type-name conflicts with an autogenerated one (again, unless they
|
163 | 196 | # request the exact same fields). They must even have the fields in the
|
164 |
| - # same order. Fragments are often easier to use (see the discussion of |
165 |
| - # code-sharing in FAQ.md, and the "flatten" option above). |
| 197 | + # same order. They should also have matching @genqlient directives, although |
| 198 | + # this is not currently validated (see issue #123). Fragments are often |
| 199 | + # easier to use (see the discussion of code-sharing in FAQ.md, and the |
| 200 | + # "flatten" option above). |
166 | 201 | #
|
167 | 202 | # Note that unlike most directives, if applied to the entire operation,
|
168 | 203 | # typename affects the overall response type, rather than being propagated
|
|
0 commit comments