Skip to content

Commit

Permalink
fix: Error nicely on missing field specifier (#782)
Browse files Browse the repository at this point in the history
Error nicely on missing field specifier
  • Loading branch information
AndrewSisley authored Sep 8, 2022
1 parent 3f6632f commit bb1f57a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 23 deletions.
2 changes: 1 addition & 1 deletion query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ func (g *Generator) genNumericAggregateBaseArgInputs(obj *gql.Object) *gql.Input

return gql.InputObjectConfigFieldMap{
"field": &gql.InputObjectFieldConfig{
Type: fieldsEnum,
Type: gql.NewNonNull(fieldsEnum),
},
parserTypes.LimitClause: &gql.InputObjectFieldConfig{
Type: gql.Int,
Expand Down
16 changes: 14 additions & 2 deletions tests/integration/query/simple/with_average_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQuerySimpleWithAverageOnUndefined(t *testing.T) {
func TestQuerySimpleWithAverageOnUndefinedObject(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, average on undefined",
Description: "Simple query, average on undefined object",
Query: `query {
_avg
}`,
Expand All @@ -28,6 +28,18 @@ func TestQuerySimpleWithAverageOnUndefined(t *testing.T) {
executeTestCase(t, test)
}

func TestQuerySimpleWithAverageOnUndefinedField(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, average on undefined field",
Query: `query {
_avg(users: {})
}`,
ExpectedError: "Argument \"users\" has invalid value {}.\nIn field \"field\": Expected \"usersNumericFieldsArg!\", found null.",
}

executeTestCase(t, test)
}

func TestQuerySimpleWithAverageOnEmptyCollection(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, average on empty",
Expand Down
16 changes: 14 additions & 2 deletions tests/integration/query/simple/with_sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQuerySimpleWithSumOnUndefined(t *testing.T) {
func TestQuerySimpleWithSumOnUndefinedObject(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, sum on undefined",
Description: "Simple query, sum on undefined object",
Query: `query {
_sum
}`,
Expand All @@ -28,6 +28,18 @@ func TestQuerySimpleWithSumOnUndefined(t *testing.T) {
executeTestCase(t, test)
}

func TestQuerySimpleWithSumOnUndefinedField(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, sum on undefined field",
Query: `query {
_sum(users: {})
}`,
ExpectedError: "Argument \"users\" has invalid value {}.\nIn field \"field\": Expected \"usersNumericFieldsArg!\", found null.",
}

executeTestCase(t, test)
}

func TestQuerySimpleWithSumOnEmptyCollection(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query, sum on empty",
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/schema/aggregates/inline_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestSchemaAggregateInlineArrayCreatesUsersSum(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
},
},
map[string]interface{}{
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestSchemaAggregateInlineArrayCreatesUsersAverage(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
},
},
map[string]interface{}{
Expand Down
44 changes: 36 additions & 8 deletions tests/integration/schema/aggregates/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func TestSchemaAggregateSimpleCreatesUsersSum(t *testing.T) {
name
type {
name
kind
ofType {
name
}
}
}
}
Expand All @@ -152,25 +156,35 @@ func TestSchemaAggregateSimpleCreatesUsersSum(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "usersNumericFieldsArg",
},
},
},
map[string]interface{}{
"name": "filter",
"type": map[string]interface{}{
"name": "usersFilterArg",
"name": "usersFilterArg",
"kind": "INPUT_OBJECT",
"ofType": nil,
},
},
map[string]interface{}{
"name": "limit",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
map[string]interface{}{
"name": "offset",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
},
Expand Down Expand Up @@ -207,6 +221,10 @@ func TestSchemaAggregateSimpleCreatesUsersAverage(t *testing.T) {
name
type {
name
kind
ofType {
name
}
}
}
}
Expand All @@ -230,25 +248,35 @@ func TestSchemaAggregateSimpleCreatesUsersAverage(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "usersNumericFieldsArg",
},
},
},
map[string]interface{}{
"name": "filter",
"type": map[string]interface{}{
"name": "usersFilterArg",
"name": "usersFilterArg",
"kind": "INPUT_OBJECT",
"ofType": nil,
},
},
map[string]interface{}{
"name": "limit",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
map[string]interface{}{
"name": "offset",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
},
Expand Down
44 changes: 36 additions & 8 deletions tests/integration/schema/aggregates/top_level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func TestSchemaAggregateTopLevelCreatesSumGivenSchema(t *testing.T) {
name
type {
name
kind
ofType {
name
}
}
}
}
Expand All @@ -135,25 +139,35 @@ func TestSchemaAggregateTopLevelCreatesSumGivenSchema(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "usersNumericFieldsArg",
},
},
},
map[string]interface{}{
"name": "filter",
"type": map[string]interface{}{
"name": "usersFilterArg",
"name": "usersFilterArg",
"kind": "INPUT_OBJECT",
"ofType": nil,
},
},
map[string]interface{}{
"name": "limit",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
map[string]interface{}{
"name": "offset",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
},
Expand Down Expand Up @@ -191,6 +205,10 @@ func TestSchemaAggregateTopLevelCreatesAverageGivenSchema(t *testing.T) {
name
type {
name
kind
ofType {
name
}
}
}
}
Expand All @@ -215,25 +233,35 @@ func TestSchemaAggregateTopLevelCreatesAverageGivenSchema(t *testing.T) {
map[string]interface{}{
"name": "field",
"type": map[string]interface{}{
"name": "usersNumericFieldsArg",
"name": nil,
"kind": "NON_NULL",
"ofType": map[string]interface{}{
"name": "usersNumericFieldsArg",
},
},
},
map[string]interface{}{
"name": "filter",
"type": map[string]interface{}{
"name": "usersFilterArg",
"name": "usersFilterArg",
"kind": "INPUT_OBJECT",
"ofType": nil,
},
},
map[string]interface{}{
"name": "limit",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
map[string]interface{}{
"name": "offset",
"type": map[string]interface{}{
"name": "Int",
"name": "Int",
"kind": "SCALAR",
"ofType": nil,
},
},
},
Expand Down

0 comments on commit bb1f57a

Please sign in to comment.