object style where input types#13
Conversation
vinpac
left a comment
There was a problem hiding this comment.
Hey, thanks for your pull request. It's great to have someone willing to help.
I wrote some reviews on things I think we could improve. I miss the checks to see how it goes with tests, but I imagine some of them probably broke since it's currently written on the old format. Could you help me updating the tests and making them pass with this new architecture?
CircleCi didn't run checks on this pull because it comes from a fork. I checked the option to do this on the project settings, so your next commit will trigger the checks. Yay!
Thanks again.
| const whereStringInputType = inputObjectType({ | ||
| name: 'whereStringInputType', |
There was a problem hiding this comment.
I think StringFilter will be more clear.
const stringFilterInputType = inputObjectType({
name: 'StringFilter',
| const whereIntInputType = inputObjectType({ | ||
| name: 'whereIntInputType', |
There was a problem hiding this comment.
I think IntFilter will be more clear.
const intFilterInputType = inputObjectType({
name: 'IntFilter',
| const whereIntInputType = inputObjectType({ | ||
| name: 'whereIntInputType', | ||
| definition(t) { | ||
| t.int('eq') |
There was a problem hiding this comment.
I think equals makes more verbose queries.
{ post (where: { id: { equals: 1 } } ) }
Rather than
{ post (where: { id: { eq: 1 } } ) }
| t.field(`${column.propertyName}_${singleOperandOperation}`, { | ||
| type: columnTypeName!, | ||
| t.field(column.propertyName, { | ||
| type: whereStringInputType!, |
There was a problem hiding this comment.
I didn't know we could pass the direct object to the type. To mantain a pattern for now. What do you think of including the inputObject at the src/plugin.ts:42?
return [
buildEntityFieldOutputMethod(manager),
buildCRUDOutputMethod(manager),
buildEntityOutputProperty(manager),
buildEntityFieldsOutputMethod(manager),
buildCRUDOutputProperty(manager),
GraphQLDateTime,
StringFilterInput,
IntFilterInput,
]
| type: whereStringInputType!, | |
| type: 'StringFilter' |
There was a problem hiding this comment.
Ok, no problem, it's your lib. But generally speaking I prefer using the object directly as It boast better type support and is less error prone.
There was a problem hiding this comment.
Didn't get your last comment about plugin.ts ? Do you want to initiate the input types from this file ? (I actually don't know much about nexus-graphql plugin dev)
There was a problem hiding this comment.
Yeah. Os this part we return an array defining the field creators and global types (e.g. GraphQLDateTime). Let's put StringFilter and IntFilter there for now so we don't have multiple implementations on how we are managing types. If later we find it better using the object directly, we migrate it.
I'm looking for reaching a stable version by the end of February.
There was a problem hiding this comment.
Not sure how to fix tests tho. I have to regenarate nexus types in the test forlder, and snapshot as well
There was a problem hiding this comment.
Is your test suit supposed to pass as is ?
There was a problem hiding this comment.
No, you have to adapt the tests. Let me take one test as example.
it('handles simple operations', async () => {
const result = await query(`
query {
users(where: {
- age_gt: 35,
- age_lt: 50
+ . age: { gt: 35, lt: 50 }
}) {
id
name
age
}
}`)
expect(result).toMatchObject({
users: [
{
age: 40,
id: expect.any(String),
name: 'baz',
},
],
})
})There was a problem hiding this comment.
No, I know 😉 ! I was refering to without my changes. Got almost all test running now, have a few things to work out yet tomorrow. Implementation wise, should I declare my input types in the plugin.ts file or set it up in another file like genericTypes.ts ? Because I also added an "id" input type (only equals and in) and more will come with adaptation of the sorting, and future relay-style pagination.
There was a problem hiding this comment.
Wow! Nice work. For now, let's declare it on src/args/arg-where.
a4343a0 to
d99b9f8
Compare
|
I am also adding the object structure for orderBy. Should those be declared
in arg-order ?
Looking at nexus-prisma the where type on a single object are
different than the one for a find operation. On a single object, only index
fields can be queried, without options.
What do you think ?
…On Fri, Jan 31, 2020 at 3:34 PM Vinicius Pacheco Furtado < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/entity-type-def-manager.ts
<#13 (comment)>
:
> @@ -349,29 +367,17 @@ export class EntityTypeDefManager {
) as Nexus.core.AllInputTypes
if (columnTypeName === 'String') {
singleOperandOperations.forEach(singleOperandOperation => {
- t.field(`${column.propertyName}_${singleOperandOperation}`, {
- type: columnTypeName!,
+ t.field(column.propertyName, {
+ type: whereStringInputType!,
Wow! Nice work. For now, let's declare it on src/args/arg-where.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ADJFT5EWY3VJ2N36PUXT6ZDRAQZIBA5CNFSM4KNTXHJ2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCT2CF5I#discussion_r373509256>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADJFT5BJLE6WWVRAXJ7PPHTRAQZIBANCNFSM4KNTXHJQ>
.
|
|
Also, I am proposing to remove orderBy from the single find object. If just
one is returned, there is no need for ordering.
On Fri, Jan 31, 2020 at 3:52 PM Loup Topalian <loup.topalian@gmail.com>
wrote:
… I am also adding the object structure for orderBy. Should those be
declared in arg-order ?
Looking at nexus-prisma the where type on a single object are
different than the one for a find operation. On a single object, only index
fields can be queried, without options.
What do you think ?
On Fri, Jan 31, 2020 at 3:34 PM Vinicius Pacheco Furtado <
***@***.***> wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In src/entity-type-def-manager.ts
> <#13 (comment)>
> :
>
> > @@ -349,29 +367,17 @@ export class EntityTypeDefManager {
> ) as Nexus.core.AllInputTypes
> if (columnTypeName === 'String') {
> singleOperandOperations.forEach(singleOperandOperation => {
> - t.field(`${column.propertyName}_${singleOperandOperation}`, {
> - type: columnTypeName!,
> + t.field(column.propertyName, {
> + type: whereStringInputType!,
>
> Wow! Nice work. For now, let's declare it on src/args/arg-where.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#13?email_source=notifications&email_token=ADJFT5EWY3VJ2N36PUXT6ZDRAQZIBA5CNFSM4KNTXHJ2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCT2CF5I#discussion_r373509256>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADJFT5BJLE6WWVRAXJ7PPHTRAQZIBANCNFSM4KNTXHJQ>
> .
>
|
|
So, following on this, may I change the tests, for example the on that connect a Or maybe, just set the name column on user as |
|
Ok, the pull request is good. I do not know why, one snapshot test doesn't seem to pass on the CI, but works fine on my end. I had to comment out the query complexity test in I apologize for such a big PR. I changed mainly those things :
Object style Tell me what you think. |
|
On the |
|
Hey @olup ! Nice pull request. I will have more time to review more closely later today or tomorrow. I loved the changes. I'm testing some cases to see if the On the Let's close on what we have now and discusss so the PR doesn't get too big and points to many directions, making it more dificult to merge. It's better if we divide other concerns and improvements on other PR's. Again, nice work on this PR it's a big help to this project. |
|
Cheers ! |
|
Should I add this to my PR ? |
|
Hmm, I feel like the object-style is a nice improvement to insteadOf An object-style here allows users to use It feels strange to read this. I was thinking about this and came up with an idea. I don't know how I feel about it yet. Another example in one line What do you think? It's more verbose, but can become a large object quickly. An array would do the same with less code. Let's keep the orderBy the same way it was and discuss it in another issue/PR? So we don't grow this PR. I will review it today. |
|
Ooops ! just published the AND clause. OK, I can revert it, but i really don't like having those double underscore properties. Ok, we can discuss it somewhere else. |
|
ok, just reverted. Please be careful of the |
|
Yeah, those double underscores seem strange to me too, but I think this is will be a decision with win and losses. I think I've pointed fair points about query size on my previous response, but let's keep discussing it. I think we can reach an agreement about the right way to go with I reviewed the WhereUniqueInput and improved a little bit to include For example: To enable this, we would have to declare a union input type for Sadly union types on GraphQL are still an RFC (https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md). I think the solution, for now, is checking if all columns are inside one unique index and make Don't worry about this on your PR. The changes I'm working on also include the WhereUniqueInput. I was already implementing it so will be no problem. I will solve this when I merge. |
|
Ok, You probably saw that my solution already involves multi indexes and
both unique indexes as well as column({unique : true}) ;-)
…On Tue, Feb 4, 2020 at 7:36 PM Vinicius Pacheco Furtado < ***@***.***> wrote:
Yeah, those double underscores seem strange to me too, but I think this is
will be a decision with win and losses. I think I've pointed fair points
about query size on my previous response, but let's keep discussing it. I
think we can reach an agreement about the right way to go with orderBy.
I reviewed the WhereUniqueInput and improved a little bit to include
@unique and @column({ unique: true }) columns, but I am thinking about
how can we cover multiple columns indexes.
For example:
We have the entity UserLikesPost that has a primary key id and one unique
index that combines userId and postId. Thus we could find an unique
instance by querying { id: <pk> } or { userId: <userId>, postId: <postId>
}.
To enable this, we would have to declare a union input type for
*WhereUniqueInput.
type UserLikesPostWhereUniqueInput =
| UserLikesPostWhereUniqueInputPK
| UserLikesPostWhereUniqueInput_UniqueSetUserIdAndPostId
type UserLikesPostWhereUniqueInput_UniqueSetUserIdAndPostId = {
userId: Int!
postId: Int!
}
Sadly union types on GraphQL are still an RFC (
https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md).
I think the solution, for now, is checking if all columns are inside one
unique index and make *WhereUniqueInput have all properties as required.
Otherwise, we only provide the Primary key on *WhereUniqueInput.
*Don't worry about this on your PR.* The changes I'm working on also
include the WhereUniqueInput. I was already implementing it so will be no
problem. I will solve this when I merge.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=ADJFT5GXQR4QHMWF3JBQV6DRBGYSPA5CNFSM4KNTXHJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKYWYLA#issuecomment-582052908>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADJFT5CSYFV5QO67Z7SGXODRBGYSPANCNFSM4KNTXHJQ>
.
|
| const uniqueIndices = [ | ||
| indices | ||
| .filter(index => index.isUnique) | ||
| .map(index => index.columns.map(column => column.propertyName)), | ||
| uniques.map(unique => unique.columns.map(column => column.propertyName)), | ||
| ].flat(10) |
There was a problem hiding this comment.
The comment is misleading : this allows for all unique indexes (even multi columns) AND @column({unique : true})
This is a basic implementation of what I raised in my issue. Seems to work alright, but I did not check the tests.