Skip to content

Commit

Permalink
Merge branch 'main' into i24331
Browse files Browse the repository at this point in the history
  • Loading branch information
zzau13 authored Sep 3, 2024
2 parents f33c2e4 + f2561ec commit d7b86af
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-engines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
echo "Repository Owner: $${{ github.repository_owner }}"
echo "Pull Request Author: ${{ github.actor }}"
echo "Pull Request Author Association: ${{ github.event.pull_request.author_association }}"
echo "Commit message:${{ steps.commit-msg.outputs.commit-msg }}"
# echo "Commit message:${{ steps.commit-msg.outputs.commit-msg }}"
echo "Commit message contains [integration]: ${{ contains(steps.commit-msg.outputs.commit-msg, '[integration]') }}"
- name: 'Check if commit message conatains `[integration]` and the PR author has permissions to trigger the workflow'
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,186 @@ mod many_relation {
Ok(())
}

fn schema_25103() -> String {
let schema = indoc! {
r#"model Contact {
#id(id, String, @id)
identities Identity[]
}
model Identity {
#id(id, String, @id)
contactId String
contact Contact @relation(fields: [contactId], references: [id])
subscriptions Subscription[]
}
model Subscription {
#id(id, String, @id)
identityId String
audienceId String
optedOutAt DateTime?
audience Audience @relation(fields: [audienceId], references: [id])
identity Identity @relation(fields: [identityId], references: [id])
}
model Audience {
#id(id, String, @id)
deletedAt DateTime?
subscriptions Subscription[]
}"#
};

schema.to_owned()
}

// Regression test for https://github.com/prisma/prisma/issues/25103
// SQL Server excluded because the m2m fragment does not support onUpdate/onDelete args which are needed.
#[connector_test(schema(schema_25103), exclude(SqlServer))]
async fn prisma_25103(runner: Runner) -> TestResult<()> {
// Create some sample audiences
run_query!(
&runner,
r#"mutation {
createOneAudience(data: {
id: "audience1",
deletedAt: null
}) {
id
}}"#
);
run_query!(
&runner,
r#"mutation {
createOneAudience(data: {
id: "audience2",
deletedAt: null
}) {
id
}}"#
);
// Create a contact with identities and subscriptions
insta::assert_snapshot!(
run_query!(
&runner,
r#"mutation {
createOneContact(data: {
id: "contact1",
identities: {
create: [
{
id: "identity1",
subscriptions: {
create: [
{
id: "subscription1",
audienceId: "audience1",
optedOutAt: null
},
{
id: "subscription2",
audienceId: "audience2",
optedOutAt: null
}
]
}
}
]
}
}) {
id,
identities (orderBy: { id: asc }) {
id,
subscriptions (orderBy: { id: asc }) {
id,
audienceId
}
}
}}"#
),
@r###"{"data":{"createOneContact":{"id":"contact1","identities":[{"id":"identity1","subscriptions":[{"id":"subscription1","audienceId":"audience1"},{"id":"subscription2","audienceId":"audience2"}]}]}}}"###
);
// Find contacts that include identities whose subscriptions have `optedOutAt = null` and include audiences with `deletedAt = null``
insta::assert_snapshot!(
run_query!(
&runner,
r#"query {
findManyContact(orderBy: { id: asc }) {
id,
identities(orderBy: { id: asc }) {
id,
subscriptions(orderBy: { id: asc }, where: { optedOutAt: null, audience: { deletedAt: null } }) {
id,
identityId,
audience {
id,
deletedAt
}
}
}
}
}"#
),
@r###"{"data":{"findManyContact":[{"id":"contact1","identities":[{"id":"identity1","subscriptions":[{"id":"subscription1","identityId":"identity1","audience":{"id":"audience1","deletedAt":null}},{"id":"subscription2","identityId":"identity1","audience":{"id":"audience2","deletedAt":null}}]}]}]}}"###
);

Ok(())
}

fn schema_25104() -> String {
let schema = indoc! {
r#"
model A {
#id(id, String, @id)
bs B[]
}
model B {
#id(id, String, @id)
a A @relation(fields: [aId], references: [id])
aId String
cs C[]
}
model C {
#id(id, String, @id)
name String
bs B[]
}
"#
};

schema.to_owned()
}

#[connector_test(schema(schema_25104), exclude(MongoDb))]
async fn prisma_25104(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(
&runner,
r#"
query {
findManyA {
bs(where: {
cs: {
every: {
name: { equals: "a" }
}
}
}) {
id
}
}
}
"#
),
@r###"{"data":{"findManyA":[]}}"###
);

Ok(())
}

fn schema_23742() -> String {
let schema = indoc! {
r#"model Top {
Expand All @@ -522,7 +702,7 @@ mod many_relation {
middleId Int?
middle Middle? @relation(fields: [middleId], references: [id])
#m2m(bottoms, Bottom[], id, Int)
#m2m(bottoms, Bottom[], id, Int)
}
model Middle {
Expand Down Expand Up @@ -579,6 +759,71 @@ mod many_relation {
Ok(())
}

fn schema_nested_some_filter_m2m_different_pk() -> String {
let schema = indoc! {
r#"
model Top {
#id(topId, Int, @id)
relatedMiddleId Int?
middle Middle? @relation(fields: [relatedMiddleId], references: [middleId])
#m2m(bottoms, Bottom[], bottomId, Int)
}
model Middle {
#id(middleId, Int, @id)
bottoms Bottom[]
tops Top[]
}
model Bottom {
#id(bottomId, Int, @id)
relatedMiddleId Int?
middle Middle? @relation(fields: [relatedMiddleId], references: [middleId])
#m2m(tops, Top[], topId, Int)
}
"#
};

schema.to_owned()
}

#[connector_test(schema(schema_nested_some_filter_m2m_different_pk), exclude(SqlServer))]
async fn nested_some_filter_m2m_different_pk(runner: Runner) -> TestResult<()> {
run_query!(
&runner,
r#"mutation {
createOneTop(data: {
topId: 1,
middle: { create: { middleId: 1, bottoms: { create: { bottomId: 1, tops: { create: { topId: 2 } } } } } }
}) {
topId
}}"#
);

insta::assert_snapshot!(
run_query!(&runner, r#"{
findUniqueTop(where: { topId: 1 }) {
middle {
bottoms(
where: { tops: { some: { topId: 2 } } }
) {
bottomId
}
}
}
}
"#),
@r###"{"data":{"findUniqueTop":{"middle":{"bottoms":[{"bottomId":1}]}}}}"###
);

Ok(())
}

async fn test_data(runner: &Runner) -> TestResult<()> {
runner
.query(indoc! { r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,20 +648,13 @@ fn extract_filter_scalars(f: &Filter) -> Vec<ScalarFieldRef> {
Filter::Scalar(x) => x.scalar_fields().into_iter().map(ToOwned::to_owned).collect(),
Filter::ScalarList(x) => vec![x.field.clone()],
Filter::OneRelationIsNull(x) => join_fields(&x.field),
Filter::Relation(x) => vec![join_fields(&x.field), extract_filter_scalars(&x.nested_filter)]
.into_iter()
.flatten()
.collect(),
Filter::Relation(x) => join_fields(&x.field),
_ => Vec::new(),
}
}

fn join_fields(rf: &RelationField) -> Vec<ScalarFieldRef> {
if rf.is_inlined_on_enclosing_model() {
rf.scalar_fields()
} else {
rf.related_field().referenced_fields()
}
rf.linking_fields().as_scalar_fields().unwrap_or_default()
}

fn join_alias_name(rf: &RelationField) -> String {
Expand Down

0 comments on commit d7b86af

Please sign in to comment.