I have a self-referencing schema:
type Category @table(name: "Categories", singular: "category", plural: "categories", key: ["id"]) {
id: UUID! @default(expr: "uuidV4()")
name: String!
description: String
active: Boolean
parent: Category @hasInverse(field: "children")
children: [Category]
}
In my mutation file Category_insert.gql, I have the following mutation:
mutation {
category_insertMany(
data: [
{id: "11111111-2222-3333-4444-555555555555", active: false, description: "", name: "Clothing & Accessories"},
{
id: "22222222-3333-4444-5555-666666666666",
parent: {id: "11111111-2222-3333-4444-555555555555"},
active: false,
description: "",
name: "Adult Clothing"
} ...
Now, I've played around with the syntax, so I've tried this as well...
type Category @table(name: "Categories", singular: "category", plural: "categories", key: ["id"]) {
id: UUID! @default(expr: "uuidV4()")
name: String!
description: String
active: Boolean
parent: Category @ref
}
And in my mutation file I've tried this:
mutation {
category_insertMany(
data: [
{id: "11111111-2222-3333-4444-555555555555", active: false, description: "", name: "Clothing & Accessories"},
{
id: "22222222-3333-4444-5555-666666666666",
parentId: "11111111-2222-3333-4444-555555555555",
active: false,
description: "",
name: "Adult Clothing"
} ...
The most common error I am seeing when I run:
Run (local)**, while running the firebase emulator, is **mutation, , category_insertMany (data[1]: [Category_Data!]!): misaligned columns: extra
parentId
I am not that familiar with graphQL and am just learning the new Firebase Data Connect service so any help on this would be greatly appreciated!
I was able to get it working. I had to change my mutation file.
mutation {
category_insert(
data: {id: "2709c745-34c5-495d-9c89-85c4402350bf", active: false, description: "", name: "Home & Garden"}
)
category_insertMany(
data: [
{
id: "22222222-3333-4444-5555-666666666666",
parent: {id: "2709c745-34c5-495d-9c89-85c4402350bf"},
active: false,
description: "",
name: "Adult Clothing"
}
In my original question, I was trying to add the parent category and children categories in the same _insertMany mutation.
So under the hood, graphql needed the parent record created first, then create the child records. After I made the above modification this mutation worked (I verified it in the database)