Skip to content

Commit

Permalink
fix(client): do not duplicate equals
Browse files Browse the repository at this point in the history
Related #3342
  • Loading branch information
Jolg42 committed Aug 20, 2020
1 parent 8e8412d commit c0bc0a8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,86 @@ describe('minimal where transformation', () => {
}"
`)
})

test('implicit many-to-many relation: select date equals (implicit)', () => {
const transformedDocument = getTransformedDocument({
select: {
posts: {
where: {
OR: [
{
createdAt: '2020-08-19T10:02:43.353Z',
},
],
},
},
},
})

expect(transformedDocument).toMatchInlineSnapshot(`
"query {
findManyUser {
posts(where: {
OR: [
{
createdAt: {
equals: \\"2020-08-19T10:02:43.353Z\\"
}
}
]
}) {
id
createdAt
updatedAt
published
title
content
authorId
}
}
}"
`)
})

test('implicit many-to-many relation: select date equals (explicit)', () => {
const transformedDocument = getTransformedDocument({
select: {
posts: {
where: {
OR: [
{
createdAt: { equals: '2020-08-19T10:02:43.353Z' },
},
],
},
},
},
})

expect(transformedDocument).toMatchInlineSnapshot(`
"query {
findManyUser {
posts(where: {
OR: [
{
createdAt: {
equals: \\"2020-08-19T10:02:43.353Z\\"
}
}
]
}) {
id
createdAt
updatedAt
published
title
content
authorId
}
}
}"
`)
})
})

function getTransformedDocument(select) {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/client/src/fixtures/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ model Post {
model Category {
id String @default(cuid()) @id
posts Post[] @relation("MyPostCatRelationTable")
posts Post[] @relation("MyPostCatRelationTable")
}
model NoRelations {
Expand Down
15 changes: 9 additions & 6 deletions src/packages/client/src/runtime/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,12 +986,15 @@ export function transformDocument(document: Document): Document {
}
if ((ar.isEnum || (typeof ar.argType === 'string' && isScalar(ar.argType)))) {
if (typeof ar.value !== 'object' || ar.argType === 'DateTime' || ar.argType === 'Json' || ar.value === null) {
ar.value = new Args([new Arg({
key: 'equals',
value: ar.value,
argType: ar.argType, // probably wrong but fine
schemaArg: ar.schemaArg // probably wrong but fine
})])
// if it's already an equals { X } do not add equals
if (!(ar.value instanceof Args)) {
ar.value = new Args([new Arg({
key: 'equals',
value: ar.value,
argType: ar.argType, // probably wrong but fine
schemaArg: ar.schemaArg // probably wrong but fine
})])
}
}
} else if (

Expand Down

0 comments on commit c0bc0a8

Please sign in to comment.