Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Introspection OrderArg returns null inputFields #1633

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 4 additions & 10 deletions request/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,20 +1116,14 @@ func (g *Generator) genTypeOrderArgInput(obj *gql.Object) *gql.InputObject {
continue
}
typeMap := g.manager.schema.TypeMap()
configType, isOrderable := typeMap[genTypeName(field.Type, "OrderArg")]
if gql.IsLeafType(field.Type) { // only Scalars, and enums
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: typeMap["Ordering"],
}
} else { // sub objects
configType, isOrderable := typeMap[genTypeName(field.Type, "OrderArg")]
if !isOrderable {
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: &gql.InputObjectField{},
}
} else {
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: configType,
}
} else if isOrderable { // sub objects
fields[field.Name] = &gql.InputObjectFieldConfig{
Type: configType,
}
}
}
Expand Down
16 changes: 1 addition & 15 deletions tests/integration/explain/debug/with_order_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,7 @@ func TestDebugExplainRequestWhereParentIsOrderedByItsRelatedChild(t *testing.T)
}
}`,

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"orderNode": dataMap{
"selectNode": dataMap{
"typeIndexJoin": dataMap{
"typeJoinMany": normalTypeJoinPattern,
},
},
},
},
},
},
},
ExpectedError: "Argument \"order\" has invalid value {articles: {name: ASC}}.\nIn field \"articles\": Unknown field.",
},
},
}
Expand Down
32 changes: 1 addition & 31 deletions tests/integration/explain/default/with_order_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,37 +180,7 @@ func TestDefaultExplainRequestWhereParentIsOrderedByItsRelatedChild(t *testing.T
}
}`,

ExpectedPatterns: []dataMap{
{
"explain": dataMap{
"selectTopNode": dataMap{
"orderNode": dataMap{
"selectNode": dataMap{
"typeIndexJoin": normalTypeJoinPattern,
},
},
},
},
},
},

ExpectedTargets: []testUtils.PlanNodeTargetCase{
{
TargetNodeName: "orderNode",
IncludeChildNodes: false,
ExpectedAttributes: dataMap{
"orderings": []dataMap{
{
"direction": "ASC",
"fields": []string{
"articles",
"name",
},
},
},
},
},
},
ExpectedError: "Argument \"order\" has invalid value {articles: {name: ASC}}.\nIn field \"articles\": Unknown field.",
},
},
}
Expand Down
26 changes: 1 addition & 25 deletions tests/integration/explain/execute/with_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,7 @@ func TestExecuteExplainRequestWhereParentFieldIsOrderedByChildField(t *testing.T
}
}`,

ExpectedFullGraph: []dataMap{
{
"explain": dataMap{
"executionSuccess": true,
"sizeOfResult": 2,
"planExecutions": uint64(3),
"selectTopNode": dataMap{
"orderNode": dataMap{
"iterations": uint64(3),
"selectNode": dataMap{
"iterations": uint64(3),
"filterMatches": uint64(2),
"typeIndexJoin": dataMap{
"iterations": uint64(3),
"scanNode": dataMap{
"iterations": uint64(3),
"docFetches": uint64(3),
},
},
},
},
},
},
},
},
ExpectedError: "Argument \"order\" has invalid value {articles: {pages: ASC}}.\nIn field \"articles\": Unknown field.",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/schema/default_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func buildFilterArg(objectName string, fields []argDef) Field {
"name": filterArgName,
}),
makeInputObject("_key", "IDOperatorBlock", nil),
makeInputObject("_not", "authorFilterArg", nil),
makeInputObject("_not", filterArgName, nil),
makeInputObject("_or", nil, map[string]any{
"kind": "INPUT_OBJECT",
"name": filterArgName,
Expand Down
103 changes: 103 additions & 0 deletions tests/integration/schema/input_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,109 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestInputTypeOfOrderFieldWhereSchemaHasManyRelationType(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type user {
age: Int
name: String
points: Float
verified: Boolean
group: group
}

type group {
members: [user]
}
`,
},
testUtils.IntrospectionRequest{
Request: `
query {
__type (name: "group") {
name
fields {
name
args {
name
type {
name
ofType {
name
kind
}
inputFields {
name
type {
name
ofType {
name
kind
}
}
}
}
}
}
}
}
`,
ContainsData: map[string]any{
"__type": map[string]any{
"name": "group",
"fields": []any{
map[string]any{
// Asserting only on group, because it is the field that contains `order` info we are
// looking for, additionally wanted to reduce the noise of other elements that were getting
// dumped out which made the entire output horrible.
"name": "_group",
"args": append(
trimFields(
fields{
dockeyArg,
dockeysArg,
buildFilterArg("group", []argDef{
{
fieldName: "members",
typeName: "userFilterArg",
},
}),
groupByArg,
limitArg,
offsetArg,
},
testInputTypeOfOrderFieldWhereSchemaHasRelationTypeArgProps,
),
map[string]any{
"name": "order",
"type": map[string]any{
"name": "groupOrderArg",
"ofType": nil,
"inputFields": []any{
map[string]any{
"name": "_key",
"type": map[string]any{
"name": "Ordering",
"ofType": nil,
},
},
},
},
},
).Tidy(),
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"user", "group"}, test)
}

func TestInputTypeOfOrderFieldWhereSchemaHasRelationType(t *testing.T) {
test := testUtils.TestCase{
Actions: []any{
Expand Down