GraphQL Mutation Error: “Field `parts` is not defined by type ‘ProjectInput'”

GraphQL Mutation Error: “Field `parts` is not defined by type ‘ProjectInput'”


0

I am working on a GraphQL mutation to create a project with associated phones and their parts, in other words relationship between is so: Phone can have multiple parts. I have defined a schema for querying phones along with their parts. However, I am encountering an error when trying to create a project with this data structure.

I have the following GraphQL mutation:

mutation update(
  $title: String
  $phones: [ID]
  $parts: [ID]
) {
  createProject(
    data: {
      title: $title
      phones: $phones
      parts: $parts
    }
  ) {
    data {
      id
      attributes {
        title
        phones {
          data {
            id
            attributes {
              name
              parts {
                data {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

And here are my query variables:

   {
  "title": "test",
  "phones": 28,
  "parts": [2, 6] 
}

The error message I’m getting is: "Field ‘parts’ is not defined by type ‘ProjectInput’." I have checked my schema, and it appears to be correctly defined.

Can anyone help me understand what might be causing this error and how to resolve it? Thank you!

Schema for Reference:

query GetAllPhones {
  phones(sort: "name:asc", pagination: { limit: 99999 }) {
    data {
      id
      attributes {
        parts {
          data {
            id
          }
        }
      }
    }
  }
}

Share
Improve this question

1 Answer
1

Reset to default


0

It’s expecting an array of phone IDs. Try:

{
  "title": "test",
  "phones": [28],
  "parts": [2, 6] 
}

Also please include the schema definition of the createProject mutation as well as the ProjectInput input type.

Share



Leave a Reply

Your email address will not be published. Required fields are marked *