Add "struct_references" configuration (#155)

Adds a "struct_references" configuration that will:

* Use a pointer type for struct fields that are a complex type
* The behaviour can be overridden by setting "pointer: false" in the
  proceeding comment blocks
* Sets the "omitempty: true" flag on fields matching the criteria.
  This can also be overriden by setting "omitempty: false"

Although we'd debated not setting the pointer for array elements, it did turn out to be simpler to set them everywhere and also made the documentation cleaner to have a single rule to explain.

Fixes #149.
This commit is contained in:
Nathan Stitt
2021-11-12 19:53:19 -08:00
committed by GitHub
parent 5401a62dcb
commit 2fdbb629be
5 changed files with 92 additions and 1 deletions
+4
View File
@@ -170,6 +170,10 @@ func TestGenerateWithConfig(t *testing.T) {
Generated: "generated.go",
ContextType: "github.com/Khan/genqlient/internal/testutil.MyContext",
}},
{"StructReferences", "", &Config{
StructReferences: true,
Generated: "generated-structrefs.go",
}},
{"NoContext", "", &Config{
Generated: "generated.go",
ContextType: "-",