Skip to content

Commit

Permalink
Require one-one to declare primary side
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Mar 27, 2024
1 parent bd427f3 commit 2bf7967
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions request/graphql/schema/descriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestSingleSimpleType(t *testing.T) {
type Author {
name: String
age: Int
published: Book
published: Book @primary
}
`,
targetDescs: []client.CollectionDefinition{
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestSingleSimpleType(t *testing.T) {
type Author {
name: String
age: Int
published: Book @relation(name:"book_authors")
published: Book @relation(name:"book_authors") @primary
}
`,
targetDescs: []client.CollectionDefinition{
Expand Down
8 changes: 1 addition & 7 deletions request/graphql/schema/relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@ func (r *Relation) finalize() error {
if aBit.isSet(relation_Type_Primary) {
return ErrMultipleRelationPrimaries
} else if !xBit.isSet(relation_Type_Primary) {
// neither type has primary set, auto add to
// lexicographically first one by schema type name
if strings.Compare(r.schemaTypes[0], r.schemaTypes[1]) < 1 {
r.types[1] = r.types[1] | relation_Type_Primary
} else {
r.types[0] = r.types[0] | relation_Type_Primary
}
return client.NewErrPrimarySideNotDefined(r.name)

Check warning on line 127 in request/graphql/schema/relations.go

View check run for this annotation

Codecov / codecov/patch

request/graphql/schema/relations.go#L127

Added line #L127 was not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/gen/gen_auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestAutoGenerateFromSchema_RelationOneToOne(t *testing.T) {
}
type Device {
owner: User
owner: User @primary
model: String
}`

Expand Down Expand Up @@ -792,7 +792,7 @@ func TestAutoGenerateFromSchema_ConfigThatCanNotBySupplied(t *testing.T) {
type Device {
model: String
owner: User
owner: User @primary
}`,
options: []Option{WithTypeDemand("User", 10), WithTypeDemand("Device", 30)},
},
Expand All @@ -801,12 +801,12 @@ func TestAutoGenerateFromSchema_ConfigThatCanNotBySupplied(t *testing.T) {
type User {
name: String
device: Device
orders: Order
orders: Order @primary
}
type Device {
model: String
owner: User
owner: User @primary
}
type Order {
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/backup/one_to_one/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func TestBackupExport_DoubleReletionship_NoError(t *testing.T) {
}
type Book {
name: String
author: User @relation(name: "written_books")
favourite: User @relation(name: "favourite_books")
author: User @relation(name: "written_books") @primary
favourite: User @relation(name: "favourite_books") @primary
}
`,
},
Expand Down Expand Up @@ -122,8 +122,8 @@ func TestBackupExport_DoubleReletionshipWithUpdate_NoError(t *testing.T) {
}
type Book {
name: String
author: User @relation(name: "written_books")
favourite: User @relation(name: "favourite_books")
author: User @relation(name: "written_books") @primary
favourite: User @relation(name: "favourite_books") @primary
}
`,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/backup/one_to_one/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ func TestBackupImport_DoubleRelationshipWithUpdate_NoError(t *testing.T) {
}
type Book {
name: String
author: User @relation(name: "written_books")
favourite: User @relation(name: "favourite_books")
author: User @relation(name: "written_books") @primary
favourite: User @relation(name: "favourite_books") @primary
}
`,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/explain/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ var SchemaForExplainTests = testUtils.SchemaUpdate{
verified: Boolean
books: [Book]
articles: [Article]
contact: AuthorContact
contact: AuthorContact @primary
}
type AuthorContact {
cell: String
email: String
author: Author
address: ContactAddress
address: ContactAddress @primary
}
type ContactAddress {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/index/query_with_relation_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestQueryWithIndexOnOneToOnesSecondaryRelation_IfFilterOnIndexedRelation_Sh
}
type Address {
user: User
user: User @primary
city: String @index
}`,
},
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestQueryWithIndexOnOneToTwoRelation_IfFilterOnIndexedRelation_ShouldFilter
}
type Address {
user: User
user: User @primary
city: String @index
}`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func execute(t *testing.T, test testUtils.TestCase) {
name: String
rating: Float
author: Author
publisher: Publisher
publisher: Publisher @primary
}
type Author {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func execute(t *testing.T, test testUtils.TestCase) {
name: String
rating: Float
author: Author
publisher: Publisher
publisher: Publisher @primary
}
type Author {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/schema/relations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSchemaRelationOneToOne(t *testing.T) {
Schema: `
type Dog {
name: String
user: User
user: User @primary
}
type User {
dog: Dog
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/view/one_to_one/with_transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestView_OneToOneWithTransformOnOuter(t *testing.T) {
}
type Book {
name: String
author: Author
author: Author @primary
}
`,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/predefined/gen_predefined_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGeneratePredefinedFromSchema_OneToOne(t *testing.T) {
}
type Device {
model: String
owner: User
owner: User @primary
}`

docs, err := CreateFromSDL(schema, DocsList{
Expand Down

0 comments on commit 2bf7967

Please sign in to comment.