-
Notifications
You must be signed in to change notification settings - Fork 54
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: Handle order input field argument being nil #701
Conversation
a6f57b1
to
64de62d
Compare
Codecov Report
@@ Coverage Diff @@
## develop #701 +/- ##
===========================================
- Coverage 58.55% 58.53% -0.02%
===========================================
Files 150 150
Lines 16884 16900 +16
===========================================
+ Hits 9887 9893 +6
- Misses 6074 6083 +9
- Partials 923 924 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From your description I'm not sure if this is a draft PR or one that is ready to go. 🧐
But I see that the commit message says WIP so that answers my question 😄 |
Sorry @fredcarle is my bad this should have been a draft just looking for feedback on how to support the failing test. |
4f55a47
to
e6e7701
Compare
e6e7701
to
fa834d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but have a couple more suggestions for you, and a test or two that fails before the fix goes in would be great :)
Type: g.manager.schema.TypeMap()[genTypeName(field.Type, "OrderArg")], | ||
configType, isOrderable := typeMap[genTypeName(field.Type, "OrderArg")] | ||
if !isOrderable { | ||
fields[field.Name] = &gql.InputObjectFieldConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: This does look incorrect, are you sure this is desired? It looks like you are adding unorderable fields to the ordering gql type. Some tests would be quite good to have here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR we were adding everything and having Type: nil
which was causing the error. We already have this test under: tests/integration/query/one_to_one/with_order_test.go
which fails if you remove this.
func TestQueryOneToOneWithChildBooleanOrderDescending(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "One-to-one relation query with simple order by sub type",
Query: `query {
book(order: {author: {verified: DESC}}) {
name
rating
author {
name
age
}
}
}`,
Docs: map[int][]string{
//books
0: {
// bae-fd541c25-229e-5280-b44b-e5c2af3e374d
`{
"name": "Painted House",
"rating": 4.9
}`,
// bae-d432bdfb-787d-5a1c-ac29-dc025ab80095
`{
"name": "Theif Lord",
"rating": 4.8
}`,
},
//authors
1: {
// bae-41598f0c-19bc-5da6-813b-e80f14a10df3
`{
"name": "John Grisham",
"age": 65,
"verified": true,
"published_id": "bae-fd541c25-229e-5280-b44b-e5c2af3e374d"
}`,
// bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04
`{
"name": "Cornelia Funke",
"age": 62,
"verified": false,
"published_id": "bae-d432bdfb-787d-5a1c-ac29-dc025ab80095"
}`,
},
},
Results: []map[string]interface{}{
{
"name": "Painted House",
"rating": 4.9,
"author": map[string]interface{}{
"name": "John Grisham",
"age": uint64(65),
},
},
{
"name": "Theif Lord",
"rating": 4.8,
"author": map[string]interface{}{
"name": "Cornelia Funke",
"age": uint64(62),
},
},
},
}
executeTestCase(t, test)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we need to test that the gql types/schema is correct, for both a valid order(able) field, and a field that is not orderable - something under test/integration/schema
} | ||
} | ||
`, | ||
ExpectedData: map[string]interface{}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly recommend using ContainsData
instead of ExpectedData
here - currently the test will fail if stuff it is not concerned about changes (making the test more complex, and raising the cost of changing those elements)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I was planning to change it once I find out if anything in the ExpectedData
changes with new code changes or not that were introduced in this PR (answer to that for this schema test is nothing changes. lmk if there are any other fields I should introspect according to you),
|
||
func TestInputTypeOfComplexSchema(t *testing.T) { | ||
test := QueryTestCase{ | ||
Schema: []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Why is this schema so complex? I cannot tell what this test is trying to test - is looks like it is trying to test everything! Please reduce the scope and use smaller, more specific test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that once I find the actual input order element that I am looking for (which was previously Type: nil
and now Type: &gql.InputObjectField{}
).
855d618
to
4fb13d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just have one low priority suggestion that I think should be addressed.
query/graphql/schema/generate.go
Outdated
@@ -216,7 +215,9 @@ func (g *Generator) fromAST(ctx context.Context, document *ast.Document) ([]*gql | |||
return defs, nil | |||
} | |||
|
|||
func (g *Generator) expandInputArgument(obj *gql.Object) error { | |||
func (g *Generator) expandInputArgument( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I think we should keep try to keep fonction definitions on one line when it doesn't reduce redability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest this is dev/reviewer preference thing and does not matter (even if Shahzad accidentally did this in this instance) - I have known plenty of devs who much prefer this format, and unless we agree to add a linter to enforce this I don't think it should really come up in reviews
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not just just a personal preference. It's what the go community prefers: https://github.com/golang/go/wiki/CodeReviewComments#line-length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a declared personal preference of the developers involved in writing that doc. Unless we add a linter it will only waste time in reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linters aren't the solution for every idiom. If the community finds that something is a best practice, we should make the effort to follow it. This is why Go is so easy to jump from one project to an other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to disagree with you there that this type of line-formatting preference makes Go projects easier to pick up. It'll also be fairly inconsistently enforced without a linter (if the team want to follow this we should find one, as it is wasteful and error prone to rely on eyeballing this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say it's part of it. The combination of all the idioms and community guidelines makes the language very approachable.
In any case, this was a suggestion. Shahzad does't have to follow it if he doesn't want to. I just think we should make an effort to follow guidelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make this change mostly because undoing the ctx
change, this looks like a random diff. However, I agree with Andy that this is a very personal preference if I did let's say kept the ctx
parameter I would like them on separate lines (unless enforced by linter). I don't think GoLang peepz cared much about this as it isn't built into gofmt
. Also very subjective if this makes it easy to pick up go projects, or improves readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test is looking better, but still needs more work before merging I think - sorry about the hassle
"testing" | ||
) | ||
|
||
func TestInputTypeOfComplexSchema(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: It is better IMO, but it is still very very unclear what this test is trying to test, a few suggestions to hopefully bring the targets more into focus (I write these assuming you are testing the order elements):
- The test name is still very unhelpful
- I still see no reason for defining 3 types in the schema
- Comments within the test might help explain why some stuff is (or isnt here)
- Asserting on the
_group
field instead of the object/query-field is odd, what did it look like when you try assert on that directly? (If it is horrible, consider documenting this) - You could perhaps look at the contents of
default_fields.go
, doing something similar for input fields could help draw attention (and maintenance effort) away from the noise, hopefully leaving the order stuff defined explicitly within the test, and all else via consts/helper funcs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will apply the todo
and report back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers Shahzad - I'm also about to start writing a similar set of tests (probs tomorrow morning) for filter - give me a shout in the meantime if you end up making any changes to the shared code, or find a handy way of targeting order and I'll try keep mine consistent with yours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some changes according to your suggestions, in the latest commit.
3254315
to
82e788d
Compare
0c94263
to
517742c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved! Thanks for the testing effort here Shahzad, am surprised how nice you got it looking (what are your thoughts on it and the format?). Got a question or two, but looks good :)
} | ||
} | ||
`, | ||
ContainsData: map[string]any{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: This looks much more focused than I was expecting! Thank you very much.
defaultGroupArgsWithoutOrder
still exists, and I am curious as to whether we'll end up tripping over it and will need to keep tweaking it with unrelated changes long term, but now it is very clear what the test cares about.
Am curious if we can do something similar for explain, and am looking forward to having a play with this (as mentioned am planning on writing similar tests this morning)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha thanks for the nudge in the right direction.
Good point, was wondering the same, if we do end up tripping over it, should be able to further break it down into their own individual defaults (not sure how much that would help though).
Funny you mention that, I actually did something similar for explain test refactor when you left for vacation last month, I been wanted to open a draft for feedback however I keep prioritizing 0.3.1 tasks as explain test refactor needs slight more work and is marked for 0.4. Will ping you for feedback on it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice sounds good :)
"ofType": any(nil), | ||
}, | ||
}, | ||
// Without the relation type we won't have the following ordering type(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cheers :)
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks :)
517742c
to
9046555
Compare
Thanks! I do like the format much better here as |
- Resolves sourcenetwork#700 - Description: This was a bug in (`generate.go`).`genTypeOrderArgInput` where if a [`field.Type` + "OrderArg"] key didn't exist in the `typeMap` it would return `nil` and pass that in `InputObjectFieldConfig` to `Type`.
Relevant issue(s)
Resolves #700
Description
This was a bug in (
generate.go
).genTypeOrderArgInput
where if a [field.Type
+ "OrderArg"] key didn't exist in thetypeMap
it would returnnil
and pass that inInputObjectFieldConfig
toType
.Tasks
How has this been tested?
ci and local
Specify the platform(s) on which this was tested: