Skip to content

Commit

Permalink
fix: Introspection OrderArg returns null inputFields (#1633)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #1632 
Resolves #1502 
Resolves #1463

## Description

This PR adds an introspection test that identifies an issue with
`orderArg`.

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

`make test`

Specify the platform(s) on which this was tested:
- MacOS
  • Loading branch information
nasdf authored Jul 13, 2023
1 parent 9611024 commit 808d6be
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 82 deletions.
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

0 comments on commit 808d6be

Please sign in to comment.