1 Answer
- Newest
- Most votes
- Most comments
1
Hi!
Assuming you want to:
- Create a new Component (not already persisted on your datasource)
- Create a new Category (not already persisted on your datasource)
- Create a new Product
You could execute multiple mutation in this way:
mutation CreateProductAndComponentsAndCategories(...){
product: createProduct(input: {...}){
id
}
# Create product's component
firstComponent: createComponent(input: {...}){
id
}
# Create product's component
secondComponent: createComponent(input: {...}){
id
}
# Create product's category
firstCategory: createCategory...
}
If instead you intended to call the mutation createProduct and also providing a list of components and categories I think it is not possible.
This is because a mutation can be connected to a single DataSource and in your case the models should have 3 different DS:
- Product -> ProductDS
- Component -> ComponentDS
- Category -> CategoryDS
For the same reason, even creating a custom mutation mapping template would not solve the problem.
Try taking a look at Pipeline Resolvers. You should be able to create a pipeline that takes Product, Components and Categories as input which in turn calls 3 distinct functions.
Hypothetically:
- Function 1: create the components
- Function 2: create categories
- Function 3: creates the product by associating the keys of the components and categories of functions 1 and 2
I've never tried pipelined mutations, but theoretically they should work! :-)
answered 2 years ago
Relevant content
- Accepted Answerasked 2 years ago
- asked 5 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
I have the same problem, I would like to populate all tables starting from a complete json object. I am wondering if there is a way to accomplish this