How to create new record of related tables without mandatory fields

I have 2 tables:

  1. Contacts
  2. Company
    They are having many to one relationship which means i can add company when creating contact record.
    Problem is i want to make company field optional in contact, i am able to do it and can add record from table directly but not able to create record through query.
    Could you please help me with it.
    Sharing example below

mutation (
$name: String!
$companyName: String // getting error here, type should be String!
) {
contactCreate(
data: {
name: $name
company: {
create: {
companyName: $companyName
}
}
}
) {
id
}
}

Thanks

Hello!
I’ve checked this on a basic example similar to your schema (one-to-many, Author → Posts):

mutation {
  authorsTableCreate(data:{
    name: "Edgar Poe"
    posts:{
      create: {
        title: "The Raven"
      }
    }
  }){
    id
  }
}

I tried it with variables also, worked fine for me.
Make sure you provide a variable in the right format like this:

{
  "companyName": "hello"
}

Can you post a screenshot from your API Explorer page with opened variables section and also show me your schema?

1 Like