Mutation: Create node with preset values?

prisma

#1

Type Output contains titles which user can modify

type Output {
 title: String
 ...
}

but titles are also pre-set through another Type serving as a template:

type OutputTemplate {
 suggestedTitle: "foo"
 ...
}

They are related through parent IDs but as Types are different otherwise they can not be relation based.

How can I create new Output with titles prefetched from OutputTemplate?

mutation {
  createOutput(
    data: {
      ...
    	titles: { create [fetch ] }
    }
   )
  }
}

Or should I create empty titles [] and then update?


#2

What stops you from first querying the OutputTemplate node with the template information, and then plugging it into the createOutput mutation accordingly? I feel like I’m missing something here :slight_smile:


#3

I simply cannot find supported syntax to do that in single query, I am trying to avoid roundtrips.


#4

What I didn’t know at the time was that I needed custom resolvers for this… aka create a GraphQL server “yoga style”. I was just using the basic CRUD on Prisma demo server.

A newbie learning step!