skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    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)


  2. I’m trying to implement a many-to-many relationship similar to what you’ve done, but I’m encountering a compile error with the schema.

    Is it working on your end? If so, would you mind taking a look at my schema and seeing if you notice anything that might be causing the issue?

    Thank you in advance for your help!

    type User
      @table(name: "Users", singular: "user", plural: "users", key: ["id"]) {
      id: UUID! @col(name: "uid") @default(expr: "uuidV4()")
      username: String! @col(name: "username") @unique
      offices: [Office] 
    }
    
    
    type Office
      @table(name: "offices", singular: "office", plural: "offices", key: ["id"]) {
      id: UUID! @col(name: "office_id")
      name: String! @col(name: "name") @unique
      users: [User]
    }
    

    The error is:

    On User.offices: Does not support array reference field. For
    one-to-many relation, define the singular reference field like
    Office.user: User!Firebase Data Connect: Compiler

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search