github.com/nathanstitt/genqlient@v0.3.1-0.20211028004951-a2bda3c41ab8/docs/genqlient.yaml (about)

     1  # genqlient.yaml is genqlient's configuration file.  This genqlient.yaml is an
     2  # example; use `go run github.com/Khan/genqlient --init` to generate a simple
     3  # starting point.  By default, genqlient looks for the configuration file
     4  # named [.]genqlient.y[a]ml in the current directory or any ancestor; or the
     5  # filename may be given as an argument.
     6  
     7  # The filename with the GraphQL schema (in SDL format), relative to
     8  # genqlient.yaml.
     9  # This can also be a list of filenames, such as:
    10  #  schema:
    11  #  - user.graphql
    12  #  - ./schema/*.graphql
    13  #  - ./another_directory/*/*.graphql
    14  schema: schema.graphql
    15  
    16  # Filename(s) or globs with the operations for which to generate code, relative
    17  # to genqlient.yaml.
    18  #
    19  # These may be .graphql files, containing the queries in SDL format, or
    20  # Go files, in which case any string-literal starting with (optional
    21  # whitespace and) the string "# @genqlient" will be extracted as a query.
    22  #
    23  # Like schema, this may be a single file or a list.
    24  operations:
    25  - genqlient.graphql
    26  - "pkg/*.go"
    27  
    28  # The filename to which to write the generated code, relative to
    29  # genqlient.yaml.
    30  generated: generated/genqlient.go
    31  
    32  # The package name for the output code; defaults to the directory name of
    33  # the generated-code file.
    34  package: mygenerated
    35  
    36  # If set, a file at this path (relative to genqlient.yaml) will be generated
    37  # containing the exact operations that genqlient will send to the server.
    38  #
    39  # This is useful for systems which require queries to be explicitly
    40  # safelisted (e.g. [1]), especially for cases like queries involving fragments
    41  # where it may not exactly match the input queries, or for other static
    42  # analysis.  The JSON is an object of the form
    43  #  {"operations": [{
    44  #      "operationName": "operationname",
    45  #      "query": "query operationName { ... }",
    46  #      "sourceLocation": "myqueriesfile.graphql",
    47  #  }]}
    48  # Keys may be added in the future.
    49  #
    50  # By default, no such file is written.
    51  #
    52  # [1] https://www.apollographql.com/docs/studio/operation-registry/
    53  export_operations: operations.json
    54  
    55  # Set to the fully-qualified name of a Go type which generated helpers
    56  # should accept and use as the context.Context for HTTP requests.
    57  #
    58  # Defaults to context.Context; set to "-" to omit context entirely (i.e.
    59  # use context.Background()).  Must be a type which implements
    60  # context.Context.
    61  context_type: context.Context
    62  
    63  # If set, a function to get a graphql.Client, perhaps from the context.
    64  # By default, the client must be passed explicitly to each genqlient
    65  # generated query-helper.
    66  #
    67  # This is useful if you have a shared client, either a global, or
    68  # available from context, and don't want to pass it explicitly.  In this
    69  # case the signature of the genqlient-generated helpers will omit the
    70  # `graphql.Context` and they will call this function instead.
    71  #
    72  # Must be the fully-qualified name of a function which accepts a context
    73  # (of the type configured as ContextType (above), which defaults to
    74  # `context.Context`, or a function of no arguments if ContextType is set
    75  # to the empty string) and returns (graphql.Client, error).  If the
    76  # client-getter returns an error, the helper will return the error
    77  # without making a query.
    78  client_getter: "github.com/you/yourpkg.GetClient"
    79  
    80  # A map from GraphQL type name to Go fully-qualified type name to override
    81  # the Go type genqlient will use for this GraphQL type.
    82  #
    83  # This is primarily used for custom scalars, or to map builtin scalars
    84  # to a nonstandard type that is defined elsewhere.  By default,
    85  # builtin scalars are mapped to the obvious Go types (String and ID to
    86  # string, Int to int, Float to float64, and Boolean to bool), but this
    87  # setting will extend or override those mappings.  (See also
    88  # @genqlient(typename: ...), which can be used to map builtin scalars
    89  # to a nonstandard type that genqlient defines for you.)
    90  #
    91  # genqlient does not validate these types in any way; they must define
    92  # whatever logic is needed (MarshalJSON/UnmarshalJSON or JSON tags) to
    93  # convert to/from JSON.  For this reason, it's not recommended to use this
    94  # setting to map object, interface, or union types, because nothing
    95  # guarantees that the fields requested in the query match those present in
    96  # the Go type.
    97  #
    98  # To get equivalent behavior in just one query, use @genqlient(bind: ...);
    99  # see genqlient_directive.graphql for more details.
   100  bindings:
   101    # To bind a scalar:
   102    DateTime:
   103      # The fully-qualified name of the Go type to which to bind.  For example:
   104      #  time.Time
   105      #  map[string]interface{}
   106      #  github.com/you/yourpkg/subpkg.MyType
   107      # Specifically, this can be any of the following expressions:
   108      # - any named type (qualified by the full package path)
   109      # - any predeclared basic type (string, int, etc.)
   110      # - interface{}
   111      # - for any allowed type T, *T, []T, [N]T, and map[string]T
   112      # but can't be, for example:
   113      # - an inline (unnamed) struct or interface type
   114      # - a map whose key-type is not string
   115      # - a nonstandard way of spelling those, (interface {/* hi */},
   116      #   map[  string      ]T)
   117      type: time.Time
   118      # Optionally, the fully-qualified name of the function to use when
   119      # marshaling this type.
   120      #
   121      # This is useful when you want to bind to a standard type, but use
   122      # nonstandard marshaling, for example when making requests to a server
   123      # that's not compatible with Go's default time format. It is only used for
   124      # types passed as arguments, i.e. input types, scalars, and enums.
   125      #
   126      # The function should have a signature similar to json.Marshal, i.e., it
   127      # will be passed one argument which will be a pointer to a value of the
   128      # given type, and must return two values: the JSON as a `[]byte`, and an
   129      # error. For example, you might specify
   130      #  unmarshaler: github.com/you/yourpkg.MarshalMyType
   131      # and that function is defined as e.g.:
   132      #  func MarshalMyType(v *MyType) ([]byte, error)
   133      #
   134      # Note that the `omitempty` option is ignored for types with custom
   135      # marshalers; the custom marshaler can of course choose to map any value it
   136      # wishes to `"null"` which in GraphQL has the same effect.
   137      # 
   138      # The default is to use ordinary JSON-marshaling.
   139      marshaler: github.com/you/yourpkg.MarshalDateTime
   140      # Optionally, the fully-qualified name of the function to use when
   141      # unmarshaling this type.
   142      #
   143      # This is similar to marshaler, above, but for unmarshaling.  The specified
   144      # function should have a signature similar to json.Unmarshal, i.e., it will
   145      # be passed two arguments, a []byte of JSON to unmarshal and a pointer to a
   146      # value of the given type, and must return an error.  For example, you
   147      # might specify
   148      #  unmarshaler: github.com/you/yourpkg.UnmarshalMyType
   149      # and that function is defined as e.g.:
   150      #  func UnmarshalMyType(b []byte, v *MyType) error
   151      # 
   152      # The default is to use ordinary JSON-unmarshaling.
   153      unmarshaler: github.com/you/yourpkg.UnmarshalDateTime
   154  
   155    # To bind an object type:
   156    MyType:
   157      type: github.com/you/yourpkg.GoType
   158      # If set, a GraphQL selection which must exactly match the fields
   159      # requested whenever this type is used.  Only applies if the GraphQL type
   160      # is a composite output type (object, interface, or union).
   161      # 
   162      # This is useful if Type is a struct whose UnmarshalJSON or other methods
   163      # expect that you requested certain fields.  For example, given the below
   164      # config, genqlient will reject if you make a query
   165      #    { fieldOfMytype { id title } }
   166      # The fields must match exactly, including the ordering: "{ name id }"
   167      # will be rejected.  But the arguments and directives, if any, need not
   168      # match.
   169      # 
   170      # TODO(benkraft): Also add ExpectIncludesFields and ExpectSubsetOfFields,
   171      # or something, if you want to say, for example, that you have to request
   172      # certain fields but others are optional.
   173      expect_exact_fields: "{ id name }"
   174      # unmarshaler and marshaler are also valid here, see above for details.