I created a separate React Component to upload fil...
# prisma-whats-new
h
I created a separate React Component to upload files, and it’s working great, but struggling to do the gql mutation for adding the relation to this File. I have Project model that has a relation field to the File. Is the ID for the File enough to be passed to the mutation, and how’s the formatting? I’m following the tutorial, but I believe Graph.cool has changed how files work at some point.
n
@hellojere hey does the project already exist? if yes, you need both the file id and the project id to connect the two 🙂
h
Ahh, no it doesn’t, I’m creating a new one.
n
Cool so how is the relation field for the file called on the
Project
model?
h
The schema has
image: File @relation(name: “ProjectImage”)
n
cool, and do you already have a
createProject
mutation that we can adjust>
h
Yes, I got:
Copy code
mutation addProject(
    $client: String!,
    $description: String!,
    $footer1: String!,
    $footer2: String!,
    $footer3: String!,
    $footer4: String!,
    $side: String!,
    $slug: String!,
    $soundcloudUrl: String!,
    $thumbnail: String!,
    $title: String!,
    $title2: String!,
    $videoUrl: String!
  ) {
    createProject(
      client: $client,
      description: $description,
      footer1: $footer1,
      footer2: $footer2,
      footer3: $footer3,
      footer4: $footer4,
      side: $side,
      slug: $slug,
      soundcloudUrl: $soundcloudUrl,
      thumbnail: $thumbnail,
      title: $title,
      title2: $title2,
      videoUrl: $videoUrl,
    ) {
      id
      side
      slug
    }
  }
n
Copy code
mutation addProject(
  $client: String!,
  $description: String!,
  $footer1: String!,
  $footer2: String!,
  $footer3: String!,
  $footer4: String!,
  $imageId: ID!,
  $side: String!,
  $slug: String!,
  $soundcloudUrl: String!,
  $thumbnail: String!,
  $title: String!,
  $title2: String!,
  $videoUrl: String!
) {
  createProject(
    client: $client,
    description: $description,
    footer1: $footer1,
    footer2: $footer2,
    footer3: $footer3,
    footer4: $footer4,
    imageId: $imageId,
    side: $side,
    slug: $slug,
    soundcloudUrl: $soundcloudUrl,
    thumbnail: $thumbnail,
    title: $title,
    title2: $title2,
    videoUrl: $videoUrl,
  ) {
    id
    side
    slug
    image {
      id
    }
  }
}
did that work? @hellojere
h
Yes! Actually did. Thought I tried that already, but it’s working. Thanks!
n
great! 🙂