-
Notifications
You must be signed in to change notification settings - Fork 44
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: Allow adding of new schema to database #635
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #635 +/- ##
===========================================
+ Coverage 57.00% 57.09% +0.09%
===========================================
Files 122 122
Lines 14636 14638 +2
===========================================
+ Hits 8343 8358 +15
+ Misses 5578 5566 -12
+ Partials 715 714 -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.
The code looks good! I'm just not sure how the test you added relate to the fix. Does it relate because users
and books
already exists and if you were defining them once again in the test case it would fail?
@@ -1266,6 +1261,16 @@ func (g *Generator) genTypeQueryableFieldList( | |||
return field | |||
} | |||
|
|||
func (g *Generator) appendIfNotExists(obj gql.Type) error { |
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(non-blocking): I read this as some element named Not
that exists. Perhaps a rename to appendIfNewSchema
or appendIfNew
?
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.
Definitely not a fan of appendIfNewSchema
, as that is incorrect/overly-specific. I'm pretty sure I have seen IfNotExists
in a number of code bases before, I don't think it is particularly uncommon. appendIfNew
might be seen as slightly misleading in another direction, suggesting that new instances (of the same name) will still be appended, but THB I don't think appendIfNotExists
vs appendIfNew
matters at all.
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.
ifNotExist
is quite fine in my opinion. I would remove the last s
though.
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.
😆 appendIfNotExists
I think fits with what I have seen before, but running it over in my head I can't quite figure out whether with the trailing s
is more or less correct than the current - I think without an s
is logically more correct, but it feels slightly wrong lol @orpheuslummis ? 🤣
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.
Go uses os.ErrNotExist
🙂
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.
Keeping it with the s
as I see this as a singular 3rd person verb lol
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.
Keeping it with the s as I see this as a singular 3rd person verb lol
feels like there is another grammar rule at play here though RE negatives - it exists
vs it does not exist
- maybe in English the negative is forced to use the infinitive? Feels weird that I dont know this stuff lol
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 like to follow what the language uses: https://pkg.go.dev/os#IsExist
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.
That's no fun though :) And it feels like that lib is breaking English, assuming exist
is not an adjective, then IsExist
should really be DoesExist
(not great programming-wise as Is
is a nice prefix for bools), or IsExisting
?
Wish I knew this stuff better lol
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.
The function I linked to is returning a bool so IsExist makes sense according to your logic. They also use it for errors: https://pkg.go.dev/os#pkg-variables
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 failed before the fix went in - each item in that testCase slice corresponds to a |
Ok thanks for clarifying :) |
Should be using the schema type map, is cleaner, and correct if adding a new schema to existing set.
79ac586
to
ae20a41
Compare
* Allow adding of new schema * Remove extra variable Should be using the schema type map, is cleaner, and correct if adding a new schema to existing set.
Relevant issue(s)
Resolves #489
Description
Allows calling
db.AddSchema
multiple times - this was broken at some point whilst implementing aggregates - the generator code would try and add existing types a second time which would error. This checks checks whether the aggregate input types already exist before trying to add them.