React Native, GraphQL, Apollo - how to create batch insert mutation
I need to create a batch insert mutation call in react native Here is my code. will you please solve my problem. I don't know where I have done a mistake. while onHandleSubmit data is not inserting in the table.
On submitting only am passing the array of object to the batch mutation call function.
onHandleSubmit = () => {
const TestResponse = [
{
id:1,
userId:123,
testId:4321,
itemId:43545,
attempt:true,
},
{
id:2,
userId:123,
testId:4321,
itemId:43546,
attempt:false,
}
];
const { ResponseStudentTestTrack = } = this.props;
ResponseStudentTestTrack(TestResponse);
}
Appsync Shema:
type StudentTestTrack {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type StudentTestTrackConnection {
items: [StudentTestTrack]
nextToken: String
}
input CreateStudentTestTrackInput {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type Mutation {
batchcreateStudentTestTrack(studentTest: [CreateStudentTestTrackInput]!): [StudentTestTrack]
}
Apollo call:
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: TestResponse,
optimisticResponse: {
__typename: 'Mutation',
batchcreateStudentTestTrack: { ...TestResponse, __typename: 'CoursePatternStatus' },
},
}),
}),
}),
mutation :
export const CreateStudentTestTrack = gql`
mutation batchcreateStudentTestTrack{
batchcreateStudentTestTrack(
studentTest:[TestResponse]
) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
react-native graphql aws-appsync appsync-apollo-client
|
show 4 more comments
I need to create a batch insert mutation call in react native Here is my code. will you please solve my problem. I don't know where I have done a mistake. while onHandleSubmit data is not inserting in the table.
On submitting only am passing the array of object to the batch mutation call function.
onHandleSubmit = () => {
const TestResponse = [
{
id:1,
userId:123,
testId:4321,
itemId:43545,
attempt:true,
},
{
id:2,
userId:123,
testId:4321,
itemId:43546,
attempt:false,
}
];
const { ResponseStudentTestTrack = } = this.props;
ResponseStudentTestTrack(TestResponse);
}
Appsync Shema:
type StudentTestTrack {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type StudentTestTrackConnection {
items: [StudentTestTrack]
nextToken: String
}
input CreateStudentTestTrackInput {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type Mutation {
batchcreateStudentTestTrack(studentTest: [CreateStudentTestTrackInput]!): [StudentTestTrack]
}
Apollo call:
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: TestResponse,
optimisticResponse: {
__typename: 'Mutation',
batchcreateStudentTestTrack: { ...TestResponse, __typename: 'CoursePatternStatus' },
},
}),
}),
}),
mutation :
export const CreateStudentTestTrack = gql`
mutation batchcreateStudentTestTrack{
batchcreateStudentTestTrack(
studentTest:[TestResponse]
) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
react-native graphql aws-appsync appsync-apollo-client
What is the type of yourResponseStudentTestTrack
which is coming from props?
– Umair Ahmed
Nov 12 '18 at 9:52
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
I dont understand then. How are you calling it like:ResponseStudentTestTrack(TestResponse);
If its an array you need to useconcat
– Umair Ahmed
Nov 12 '18 at 11:06
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39
|
show 4 more comments
I need to create a batch insert mutation call in react native Here is my code. will you please solve my problem. I don't know where I have done a mistake. while onHandleSubmit data is not inserting in the table.
On submitting only am passing the array of object to the batch mutation call function.
onHandleSubmit = () => {
const TestResponse = [
{
id:1,
userId:123,
testId:4321,
itemId:43545,
attempt:true,
},
{
id:2,
userId:123,
testId:4321,
itemId:43546,
attempt:false,
}
];
const { ResponseStudentTestTrack = } = this.props;
ResponseStudentTestTrack(TestResponse);
}
Appsync Shema:
type StudentTestTrack {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type StudentTestTrackConnection {
items: [StudentTestTrack]
nextToken: String
}
input CreateStudentTestTrackInput {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type Mutation {
batchcreateStudentTestTrack(studentTest: [CreateStudentTestTrackInput]!): [StudentTestTrack]
}
Apollo call:
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: TestResponse,
optimisticResponse: {
__typename: 'Mutation',
batchcreateStudentTestTrack: { ...TestResponse, __typename: 'CoursePatternStatus' },
},
}),
}),
}),
mutation :
export const CreateStudentTestTrack = gql`
mutation batchcreateStudentTestTrack{
batchcreateStudentTestTrack(
studentTest:[TestResponse]
) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
react-native graphql aws-appsync appsync-apollo-client
I need to create a batch insert mutation call in react native Here is my code. will you please solve my problem. I don't know where I have done a mistake. while onHandleSubmit data is not inserting in the table.
On submitting only am passing the array of object to the batch mutation call function.
onHandleSubmit = () => {
const TestResponse = [
{
id:1,
userId:123,
testId:4321,
itemId:43545,
attempt:true,
},
{
id:2,
userId:123,
testId:4321,
itemId:43546,
attempt:false,
}
];
const { ResponseStudentTestTrack = } = this.props;
ResponseStudentTestTrack(TestResponse);
}
Appsync Shema:
type StudentTestTrack {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type StudentTestTrackConnection {
items: [StudentTestTrack]
nextToken: String
}
input CreateStudentTestTrackInput {
id: ID!
userId: ID!
testId: ID!
itemId: ID!
attempt: String!
}
type Mutation {
batchcreateStudentTestTrack(studentTest: [CreateStudentTestTrackInput]!): [StudentTestTrack]
}
Apollo call:
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: TestResponse,
optimisticResponse: {
__typename: 'Mutation',
batchcreateStudentTestTrack: { ...TestResponse, __typename: 'CoursePatternStatus' },
},
}),
}),
}),
mutation :
export const CreateStudentTestTrack = gql`
mutation batchcreateStudentTestTrack{
batchcreateStudentTestTrack(
studentTest:[TestResponse]
) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
react-native graphql aws-appsync appsync-apollo-client
react-native graphql aws-appsync appsync-apollo-client
asked Nov 12 '18 at 7:15
Mageswari Radhakrishnan
82
82
What is the type of yourResponseStudentTestTrack
which is coming from props?
– Umair Ahmed
Nov 12 '18 at 9:52
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
I dont understand then. How are you calling it like:ResponseStudentTestTrack(TestResponse);
If its an array you need to useconcat
– Umair Ahmed
Nov 12 '18 at 11:06
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39
|
show 4 more comments
What is the type of yourResponseStudentTestTrack
which is coming from props?
– Umair Ahmed
Nov 12 '18 at 9:52
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
I dont understand then. How are you calling it like:ResponseStudentTestTrack(TestResponse);
If its an array you need to useconcat
– Umair Ahmed
Nov 12 '18 at 11:06
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39
What is the type of your
ResponseStudentTestTrack
which is coming from props?– Umair Ahmed
Nov 12 '18 at 9:52
What is the type of your
ResponseStudentTestTrack
which is coming from props?– Umair Ahmed
Nov 12 '18 at 9:52
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
I dont understand then. How are you calling it like:
ResponseStudentTestTrack(TestResponse);
If its an array you need to use concat
– Umair Ahmed
Nov 12 '18 at 11:06
I dont understand then. How are you calling it like:
ResponseStudentTestTrack(TestResponse);
If its an array you need to use concat
– Umair Ahmed
Nov 12 '18 at 11:06
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39
|
show 4 more comments
1 Answer
1
active
oldest
votes
There seems to something wrong with client side mutation. Try this.
export const CreateStudentTestTrack = gql`
mutation abc ( // could be anyname
$studentTest: [CreateStudentTestTrackInput] // Type of input mentioned in graphql definition
) {
batchcreateStudentTestTrack(studentTest: $studentTest) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
Also try removing optimistic response inside your graphql parameter if don't need to update ui cache and if your mutation call is just for insert. Also I have updated the mutate object based on my solutions. Please look into it too.
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: {
studentTest: TestResponse
},
}),
}),
}),
Also check you destructuring code.
const { ResponseStudentTestTrack } = this.props; // don't set default value as array for a function prop.
Try this code and you face issues comment below.
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257400%2freact-native-graphql-apollo-how-to-create-batch-insert-mutation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There seems to something wrong with client side mutation. Try this.
export const CreateStudentTestTrack = gql`
mutation abc ( // could be anyname
$studentTest: [CreateStudentTestTrackInput] // Type of input mentioned in graphql definition
) {
batchcreateStudentTestTrack(studentTest: $studentTest) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
Also try removing optimistic response inside your graphql parameter if don't need to update ui cache and if your mutation call is just for insert. Also I have updated the mutate object based on my solutions. Please look into it too.
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: {
studentTest: TestResponse
},
}),
}),
}),
Also check you destructuring code.
const { ResponseStudentTestTrack } = this.props; // don't set default value as array for a function prop.
Try this code and you face issues comment below.
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
add a comment |
There seems to something wrong with client side mutation. Try this.
export const CreateStudentTestTrack = gql`
mutation abc ( // could be anyname
$studentTest: [CreateStudentTestTrackInput] // Type of input mentioned in graphql definition
) {
batchcreateStudentTestTrack(studentTest: $studentTest) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
Also try removing optimistic response inside your graphql parameter if don't need to update ui cache and if your mutation call is just for insert. Also I have updated the mutate object based on my solutions. Please look into it too.
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: {
studentTest: TestResponse
},
}),
}),
}),
Also check you destructuring code.
const { ResponseStudentTestTrack } = this.props; // don't set default value as array for a function prop.
Try this code and you face issues comment below.
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
add a comment |
There seems to something wrong with client side mutation. Try this.
export const CreateStudentTestTrack = gql`
mutation abc ( // could be anyname
$studentTest: [CreateStudentTestTrackInput] // Type of input mentioned in graphql definition
) {
batchcreateStudentTestTrack(studentTest: $studentTest) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
Also try removing optimistic response inside your graphql parameter if don't need to update ui cache and if your mutation call is just for insert. Also I have updated the mutate object based on my solutions. Please look into it too.
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: {
studentTest: TestResponse
},
}),
}),
}),
Also check you destructuring code.
const { ResponseStudentTestTrack } = this.props; // don't set default value as array for a function prop.
Try this code and you face issues comment below.
There seems to something wrong with client side mutation. Try this.
export const CreateStudentTestTrack = gql`
mutation abc ( // could be anyname
$studentTest: [CreateStudentTestTrackInput] // Type of input mentioned in graphql definition
) {
batchcreateStudentTestTrack(studentTest: $studentTest) {
id,
userId,
testId,
itemId,
attempt,
}
}`;
Also try removing optimistic response inside your graphql parameter if don't need to update ui cache and if your mutation call is just for insert. Also I have updated the mutate object based on my solutions. Please look into it too.
graphql(CreateStudentTestTrack, {
props: props => ({
ResponseStudentTestTrack: TestResponse => props.mutate({
variables: {
studentTest: TestResponse
},
}),
}),
}),
Also check you destructuring code.
const { ResponseStudentTestTrack } = this.props; // don't set default value as array for a function prop.
Try this code and you face issues comment below.
edited Nov 15 '18 at 7:22
answered Nov 15 '18 at 6:05
Naveen Vignesh
248111
248111
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
add a comment |
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
Thank you Naveen Vignesh. It's solved my problem.
– Mageswari Radhakrishnan
Nov 15 '18 at 7:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257400%2freact-native-graphql-apollo-how-to-create-batch-insert-mutation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the type of your
ResponseStudentTestTrack
which is coming from props?– Umair Ahmed
Nov 12 '18 at 9:52
it's an array of an object like below const TestResponse = [ { id:1, userId:123, testId:4321, itemId:43545, attempt:true, }, { id:2, userId:123, testId:4321, itemId:43546, attempt:false, }
– Mageswari Radhakrishnan
Nov 12 '18 at 11:03
I dont understand then. How are you calling it like:
ResponseStudentTestTrack(TestResponse);
If its an array you need to useconcat
– Umair Ahmed
Nov 12 '18 at 11:06
yes we can able call ResponseStudentTestTrack through props.only concat values is passing via ResponseStudentTestTrack(TestResponse).
– Mageswari Radhakrishnan
Nov 12 '18 at 11:38
Just i want know how to pass array of object value in this mutation call other than its working fine for me. export const CreateStudentTestTrack = gql` mutation batchcreateStudentTestTrack{ batchcreateStudentTestTrack( studentTest:[TestResponse] ) { id, userId, testId, itemId, attempt, } }`;
– Mageswari Radhakrishnan
Nov 12 '18 at 11:39