Insert
FastGQL auto generates create<OBJECT_NAME>
insert mutations if the #generateMutations is set. The following code will be added to the GraphQL schema.
// Some code
mutation { # createPosts allows to insert one or more Posts createPosts(inputs: [CreatePostInput!]!): PostsPayload # ... more mutations}
"""AutoGenerated input for Post"""input CreatePostInput { id: Int! name: String}
"""Autogenerated payload object"""type PostsPayload { """ rows affection by mutation """ rows_affected: Int! posts: [Post]}
The #generateMutations directive adds the above into our schema.
inputs
argument passed tocreatePosts
mutation is required and you can pass 1 or more objects.PostsPayload
is the response object returned from the mutation, returning the amounts of rows_affected i.e. the amount of objects inserted and access to all our posts info
Insert Objects
Example: Insert a new post object
and return the inserted post object in the response:
mutation { createPosts(inputs: {name: "fastGQL", id: 111}) { rows_affected posts { name id } }
mutation { createPosts(inputs: [{name: "fastGQL", id: 1}, {name: "fastGQL2", id: 2}]) { rows_affected posts { name id } }}
mutation { createPosts(inputs: [{name: "fastGQL", id: 1}, {name: "fastGQL2", id: 2}]) { rows_affected posts { name id categories { id name } } }}