Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"github.com/pmezard/go-difflib/difflib"
)

type CyclicParent struct {
Name string
Child *CyclicChild
}

type CyclicChild struct {
Name string
Parent *CyclicParent
}

// TestMarshalQuery tests the MarshalQuery function.
func TestMarshalQuery(t *testing.T) {
tt := []struct {
Expand Down Expand Up @@ -321,6 +331,53 @@ differentField
testQuery {
overrideName
}
}`,
},
{
Name: "CyclicStructuresWithFields",
Input: struct {
TestQuery struct {
Parent *CyclicParent
}
}{},
Fields: Fields{
"parent": Fields{
"name": true,
"child": Fields{
"name": true,
},
},
},
Option: OptFallbackJSONTag,
ExpectedOutput: `query {
testQuery {
parent {
name
child {
name
}
}
}
}`,
},
{
Name: "CyclicStructuresWithoutFields",
Input: struct {
TestQuery struct {
Parent *CyclicParent
}
}{},
Fields: nil,
Option: OptFallbackJSONTag,
ExpectedOutput: `query {
testQuery {
parent {
name
child {
name
}
}
}
}`,
},
}
Expand Down
Loading