Relay directive parameters are not removed from variables, when sending request to server
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Given the following example:
```js
const [commit, isInFlight] = useMutation(
graphql`
mutation TeamFollowButton_Mutation($teamId: uuid!, $connections: [ID!]!) {
insert_team_followers(
objects: [{
team_id: $teamId
}]
) {
returning @appendNode(connections: $connections, edgeTypeName: "team_followersEdge") {
id
team_id
user_id
}
}
}
`,
)
function follow() {
commit({
variables: {
teamId: decodeID(props.team.id),
connections: [
`client:${props.team.id}:team_followers_connection`,
],
},
})
}
```
and following request body:
```json
{
"id": "TeamFollowButton_Mutation",
"query":"mutation TeamFollowButton_Mutation(\n $teamId: uuid!\n) {\n insert_team_followers(objects: [{team_id: $teamId}]) {\n returning {\n id\n team_id\n user_id\n }\n }\n}\n",
"variables":{
"teamId":"7f35e18f-49bd-46ea-b279-34dece7574cc",
"connections:"["client:WzEsICJwdWJsaWMiLCAidGVhbXMiLCAiN2YzNWUxOGYtNDliZC00NmVhLWIyNzktMzRkZWNlNzU3NGNjIl0=:team_followers_connection"]
}
}
```
in the request body "connections" was removed from the query, but it was still sent to server through variables. This makes it uneasy to work with i.e. Hasura, since they validate mutation parameters and return errors when an unexpected field is provided.
```json
{"errors":[{"extensions":{"path":"$","code":"validation-failed"},"message":"unexpected variables in variableValues: connections"}]}
```
I can imagine the issue can be fixed by Hasura (or any other server implementation), but perhaps fixing it in relay compiler/runtime is the best place for it? Is there any reason for sending variables used by internal directives (i.e.) to server?
Cheers and thanks for awesome lib!
Marcin
Contributor guide
Assessment
This issue has not been assessed yet.