as you can see my parameter has an object inside o...
# orm-help
v
as you can see my parameter has an object inside of it (user)
k
I'm just gonna be lazy and point towards my own project's code to inspire you. https://github.com/TiE23/metric-teacher/blob/6605869ff7104fa3982cb71b81d39a89766e16a7/client/src/graphql/Mutations.js#L3 It's my user signup mutation that I run with Apollo on my client. The server side is this: https://github.com/TiE23/metric-teacher/blob/6605869ff7104fa3982cb71b81d39a89766e16a7/server/src/resolvers/Mutation/auth.js#L23 Let me know if that helps ya. 👍🏻
v
@KyleG thanks man. my issue though is the fact all my fields (user, password, first_name, etc...) are wrapped a user object
how would i handle that case?
k
@vuegraphqlI believe it'd likely look like this... (Duplicating format I shared, yours might look different)
Copy code
export const CREATE_USER_MUTATION = gql`
  mutation createUser($email: String!, $password: String!, $first_name: String!, $last_name: String!, $phone_number: String!) {
  createUser(
    user: {
      email : $email,
      password : $password,
      first_name : $first_name,
      last_name : $last_name,
      phone_number : $phone_number
    }
  ) {
    metaData {
      message,
      type
    }
  }
}
`;
The variables (like
$email
) are being swapped out AFAIK, so if you simply define the user object in the mutation and fill it out like I do above that would likely work.
Oh, perhaps you're passing in the user object as an argument? Hmmm...
@vuegraphql
Copy code
# In schema.graphql
input CreateUserInput {
  email: String!
  password: String!
  first_name: String!
  last_name: String!
  phone_number: String!
}
Copy code
# In your client
export const CREATE_USER_MUTATION = gql`
  mutation createUser($create_user_input: CreateUserInput!) {
  createUser(
    user: $create_user_input
  ) {
    metaData {
      message,
      type
    }
  }
}
`;
If you're using Apollo, I'll have to point towards another example bit of code: https://github.com/TiE23/metric-teacher/blob/6605869ff7104fa3982cb71b81d39a89766e16a7/client/src/components/Login.js#L100 While my code is like so:
Copy code
const result = await this.props.signupMutation({
  variables: {
    fname: this.state.fname,
    lname: this.state.lname,
    email: utils.customNormalizeEmail(this.state.email),
    password: this.state.password,
  },
Yours might look like this:
Copy code
const result = await this.props.createUserMutation({
  variables: {
    user: {
      email: utils.customNormalizeEmail(this.state.email),
      password: this.state.password,
      first_name: this.state.first_name,
      last_name: this.state.last_name,
      phone_number: this.state.phone_number,
    },
  },
I don't know if this'll work for a fact. Actually, I'm actively writing my project right now and realized that I'll have this same exact situation as you before long with a complicated mutation input object I have. So simply this is what I would try the first time.
v
wow thanks for the long and thoughtful response!
theres a lot i have to got through, one sec
@KyleG i haven't used apollo yet, but it seems graphql-request, axios, and apollo all have the same payload structure for sending mutations and queries
Copy code
# In your client
export const CREATE_USER_MUTATION = gql`
  mutation createUser($create_user_input: CreateUserInput!) {
  createUser(
    user: $create_user_input
  ) {
    metaData {
      message,
      type
    }
  }
}
`;
so i believe your export const CREATE_USER_MUTATION = ... would work
i am going to try it out now thanks!
and it worked thanks!!!!
damn i got lucky as hell i found you, because this type of scenario is nowhere to be found elsewhere 👍
🎉 1
k
Glad I was able to help! Yeah, having people to ask straight up can be a life saver no matter how many times you scour blogs, forums, Stack Overflow pages through Google. I've been saved multiple times in this Slack channel so I try to pay back when I can. 👍🏻
💚 2
n
thanks so much for your help, Kyle 💚