Cannot pass state parameter to mutation


rebirth

I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react.

Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to this.state.data( again confirming that it was saved correctly).

On the backend, I have a mutationlike: userCreate(input: UserInput): Userit explicitly accepts this field input.

The issue is:

How to properly perform mutating bound values ​​from this.state.datafields ?

I have the following code so far:

onChange = e =>
    this.setState({
      data: { ...this.state.data, [e.target.id]: e.target.value }
    });

  handleSubmit = async () => {
    writeToLog(this.state.data)
    const { name, email, externalId, userCode} = this.state.data
    this.props.userCreateQuery({
      input: {
        name,
        email,
        externalId,
        userCode
      }
    })
  }

Here's what the mutation looks like:

const QUERY_PERSON_MUTATION = gql`
mutation userCreateQuery($name: String!, $email: String!, $externalId: String!, $userCode: String!) {
  userCreate(input: {
    Name: $name,
    Email: $email,
    ExternalId: $externalId,
    UserCode: $userCode}) {
    Name
    Email
    ExternalId
    UserCode
  }
}`;

Component packaging:

const NewUserFormWithData = graphql(QUERY_PERSON_MUTATION, { name: 'userCreateQuery' })(NewUserForm);

    export default withApollo(NewUserFormWithData)

Update 1:

Architecture:

const typeDefs = `
type User {
   UserId: Int
   /* other fields */
}

input UserInput {
   UserId: Int
   UserCode: String
   /* other fields */
}

type Mutation {
   userCreate(input: UserInput): User
   userUpdate(userId: Int, input: UserInput): User    
}`;
Alexandre France

You have to use data in variable keys:

this.props.userCreateQuery({
  variables: {
      input: {
        name,
        email,
        externalId,
        userCode
      }
  }
})

PS.: I don't know your graphql server, but you probably don't use key input for mutation work.

We have already discussed:

The mutation you entered.

 const QUERY_PERSON_MUTATION = gql`
    mutation userCreateQuery($name: String!, $email: String!, $externalId: String!, $userCode: String!) {
      userCreate(
        Name: $name,
        Email: $email,
        ExternalId: $externalId,
        UserCode: $userCode) {
        Name
        Email
        ExternalId
        UserCode
      }
    }`;

this.props.userCreateQuery({
  variables: {
      name,
      email,
      externalId,
      userCode
  }
})

Related


Pass state as parameter to ring handler?

4ZM How can I most conveniently inject state into a ring handler (without using global variables)? Here is an example: (defroutes main-routes (GET "/api/fu" [] (rest-of-the-app the-state))) (def app (-> (handler/api main-routes))) I want to the-stateente

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

How to pass hash as parameter in GraphQL Mutation

waving I am trying to pass options hash as parameter in my GraphQL mutation. I want to update multiple fields of an object based on the fields passed to mutation. It looks like this: updateStatus(statusId, options) I'm not sure how to specify the hash/object i

Can't get Vuex mutation or action to pass data to state

Jim Strother I can't pass data to application state via mutation or manipulation. Despite spending hours reading the Vuex docs, I'm not even sure I'm calling them correctly. I started creating a mutation to simply update my state when the @click event fires, b

Vuex - Pass specific state as parameter

Joe 82 In Vuex, I have two states that I want to mutate using the same function. Is there any way to pass the exact state you want to change so mutationsI don't have to repeat the same function multiple times for it to work? what i have now state: { firstp

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Pass function parameter to another function with mutation

UserOnWeb I am trying to write the following code func1Accepts a bunch of parameters (don't know in advance if it is) extraAdd one more parameter based on some logic pass (let's say ) All these parameters are passed to the next function func2. Here is what I h

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

Can't get Vuex mutation or action to pass data to state

Jim Strother I can't pass data to application state via mutation or manipulation. Despite spending hours reading the Vuex docs, I'm not even sure I'm calling them correctly. I started creating a mutation to simply update my state when the @click event fires, b

AngularJS: Pass object parameter to state

the following I want to pass an object to a state. Here's how I do it: .state('options', { url: "/options?current_task", views: { "middle": { templateUrl: "/games/options.html" } } This is what I said: $state.go("options", {cur

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

How to pass hash as parameter in GraphQL Mutation

waving I am trying to pass an options hash as a parameter in my GraphQL mutation. I want to update multiple fields of an object based on the fields passed to mutation. It looks like this: updateStatus(statusId, options) I'm not sure how to specify the hash/obj

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Pass function parameter to another function with mutation

UserOnWeb I am trying to write the following code func1Accepts a bunch of parameters (don't know in advance if it is) extraAdd one more parameter based on some logic pass (let's say ) All these parameters are passed to the next function func2. Here is what I h

Pass function parameter to another function with mutation

UserOnWeb I am trying to write the following code func1Accepts a bunch of parameters (don't know in advance if it is) extraAdd one more parameter based on some logic pass (let's say ) All these parameters are passed to the next function func2. Here is what I h

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

AngularJS: Pass object parameter to state

the following I want to pass an object to a state. Here's how I do it: .state('options', { url: "/options?current_task", views: { "middle": { templateUrl: "/games/options.html" } } This is what I said: $state.go("options", {cur