mswjs / examples

Examples of Mock Service Worker usage with various frameworks and libraries.
685 stars 211 forks source link

fix: reference username in login mutation (graphql-react-apollo) #81

Closed prscoelho closed 2 years ago

prscoelho commented 2 years ago

Changes

I was tinkering around in my own toy project while following the graphql-react-apollo example, and apollo/client was just refusing to send the variable from the mutation.

So I found out that if you don't reference a variable that you define, apollo client does not send it. So:

mutation Login($username: String!) {
  user {
    id
    firstName
    lastName
  }
}

Should be:

mutation Login($username: String!) {
  user(username: $username) {
    id
    firstName
    lastName
  }
}

But when I tested the project from the fork this issue didn't happen. It turns out that this is a new behavior that doesn't happen in "@apollo/client": "3.2.2, but it does in "@apollo/client": "^3.7.1"

However, even though with the current version this works, I think it's still wrong and should be fixed. I imagine that in the future people will be very confused by the example, as I was. So here's the fix, I didn't bump any versions, just the mutation. Let me know if you want me to bump the apollo/client version.

kettanaito commented 2 years ago

I also think we should bump the apollo client to the latest version. Would you be interested in opening a pull request?