I have the following schema, such that a User can have multiple Forms and a form can have multiple inputs. This works well as of now.
type Form {
name: String!
index: Int!
user: User
formInputVals: [FormInputVal!] @relation
}
type FormInputVal {
name: String!
index: Int!
type: String!
formRoot: Form!
}
type User {
name: String!
email: String!
password: String!
forms: [Form] @relation
}
type Query {
allForms: [Form!]
allUsers: [User!]
allFormInputVals: [FormInputVal!]
}
However my issue arrises when I try to do a mutation where I add multiple inputs at a time. See my ui will return to me an array of objects like this.
[{
"__typename": "FormInputVal",
"name": "Product Image #1",
"type": "image"
}, {
"__typename": "FormInputVal",
"name": "Description",
"type": "text"
}, {
"__typename": "FormInputVal",
"name": "Product Image",
"type": "text"
}]
I then want to create a mutation that takes all three of these objects, for a specified Form by connection ID, and creates 3 documents of the type FormInputVal. Thus the Form with say id 1234 has three associated inputs if I were to do a graphQL query for such, but in the collection FormInputVal there are three new documents.
I tried looking at @resolvers and running a fauna function, but got kinda lost. In that case I am not sure what I even pass in the mutation, currently the mutation asks for a data, with the fields on the document, but what If I wanted to pass an array of objects with the same fields.
Also is there a better way to arcitecht what I am doing? Esentially I have a form that uses react state to add new elements to itself (user generated inputs) and I want to update the DB after the user saves the entire form, not at every point they create a input because that should be handled by the state.
I also posted a much more indepth question on stack overflow if any one could take a look.