-
Notifications
You must be signed in to change notification settings - Fork 51
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: Prevent mutations from secondary side of relation #3124
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Prevent mutations from secondary side of relation | ||
|
||
The docIDs in some tests that relied on the removed behaviour have changed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,35 +94,6 @@ func TestMutationCreateOneToMany_AliasedRelationNameNonExistingRelationManySide_ | |
} | ||
executeTestCase(t, test) | ||
} | ||
func TestMutationCreateOneToMany_AliasedRelationNameInvalidIDManySide_CreatedDoc(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One to many create mutation, invalid id, from the many side, with alias", | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"author": "ValueDoesntMatter" | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Book { | ||
name | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Book": []map[string]any{ | ||
{ | ||
"name": "Painted House", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
executeTestCase(t, test) | ||
} | ||
Comment on lines
-97
to
-125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why not assert the current behavior rather than removing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are already tests that test what this test would test if it was modified to match the current behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. Cheers thanks! |
||
|
||
func TestMutationCreateOneToMany_AliasedRelationNameToLinkFromManySide(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,23 +73,6 @@ func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationPrimarySide_Creat | |
executeTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreateOneToOne_UseAliasWithNonExistingRelationSecondarySide_Error(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One to one create mutation, alias relation, from the secondary side", | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"author": "bae-be6d8024-4953-5a92-84b4-f042d25230c6" | ||
}`, | ||
ExpectedError: "document not found or not authorized to access", | ||
}, | ||
}, | ||
} | ||
executeTestCase(t, test) | ||
} | ||
Comment on lines
-76
to
-91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Similar question as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer :) |
||
|
||
func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySide(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One to one create mutation with an alias relation.", | ||
|
@@ -153,9 +136,13 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromPrimarySid | |
executeTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondarySide(t *testing.T) { | ||
func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_CollectionAPI_Errors(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One to one create mutation from secondary side with alias relation.", | ||
SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ | ||
testUtils.CollectionSaveMutationType, | ||
testUtils.CollectionNamedMutationType, | ||
}), | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
|
@@ -169,46 +156,34 @@ func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_QueryFromSecondaryS | |
"name": "Painted House", | ||
"author": testUtils.NewDocIndex(1, 0), | ||
}, | ||
ExpectedError: "cannot set relation from secondary side", | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Author { | ||
name | ||
published { | ||
name | ||
} | ||
} | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestMutationCreateOneToOne_UseAliasedRelationNameToLink_GQL_Errors(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One to one create mutation from secondary side with alias relation.", | ||
SupportedMutationTypes: immutable.Some([]testUtils.MutationType{ | ||
testUtils.GQLRequestMutationType, | ||
}), | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham" | ||
}`, | ||
Results: map[string]any{ | ||
"Author": []map[string]any{ | ||
{ | ||
"name": "John Grisham", | ||
"published": map[string]any{ | ||
"name": "Painted House", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Book { | ||
name | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Book": []map[string]any{ | ||
{ | ||
"name": "Painted House", | ||
"author": map[string]any{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
DocMap: map[string]any{ | ||
"name": "Painted House", | ||
"author": testUtils.NewDocIndex(1, 0), | ||
}, | ||
ExpectedError: "Argument \"input\" has invalid value", | ||
}, | ||
}, | ||
} | ||
|
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.
thought: the logic here and in
client.Document
is the same. Would it make sense to have afield.IsSecondaryRelation
helper function instead?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 thought about it, but decided it wasn't worth coupling them together and boost the (public) client package surface area. Especially given that the gql/schema package is begging for a re-write.