DEV Community

wolfiton
wolfiton

Posted on

1

(Solved)Graphql vue apollo define category{connect: Int!}

Hi everyone,

Solved:
Solved with the help of @benheimberg here https://stackoverflow.com/questions/62304716/how-to-create-nested-relationships-in-laravel-lighthouse-and-vue-apollo/62305347#62305347

Th repos are here

You can play with this whole project by cloning my repos https://github.com/wolfiton/booksql-laravel backend

https://github.com/wolfiton/booksql-vue frontend

mutation (

      $categoryId: ID!
)

createBook(
    input: 
      category: {connect: $categoryId]
    }

Update: Before someone will say that I can do this

category: Int!
category: $category
variables: {

        $category: this.categoryId,
      },

Unfortunately I can't because the backend framewok requires me to send the mutation like this

variables: {

        $category: { connect: this.categoryId },
      },

So any help is apreciated.

I was working graphql an I need to define the following type:

category: {connect:ID!}

mutation (
      $title: String!
      $image: String!
      $author: String!
      $description: String!
      $link: String!
      $featured: Boolean
      $category: { connect: Int! }
)
{
  createBook(
    input: {
      title: $title
      image: $image
      author: $author
      description: $description
      link: $link
      featured: $featured
      category: $category
    }
  ) {
    id
    title
    author
  }
}

My form uses model to recieve the data for the connect from a select.

I dont know how to define this variable for my mutation:

variables: {

        $category: { connect: this.categoryId },
      },

I need to replace this:

$category: { connect: Int! }

with something like this

$category: { connect: this.categoryId }

Does someone know how i can define this type?

Thanks in advance

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs