Skip to content

Surprising behavior if sendVariableValues.transform mutates variables #5060

@glasser

Description

@glasser

The variables option passed to sendVariableValues.transform is the exact object used in query execution (direct or gateway), so if you mutate it instead of just returning a copied object, you will surprisingly affect query execution. The docs even encourage you to do this:

The function should modify or delete necessary values in the variables map and return the result.

At the very least we should change the docs to tell you to not mutate the argument!

We may also want to do one or both of:

  • Using something like Suggestion: DeepReadonly<T> type microsoft/TypeScript#13923 to discourage TypeScript users from mutating the argument
  • Doing some sort of clone (JSON.parse(JSON.stringify())?) on the variables that are passed in. This approach has a performance impact and could cause problems if somehow a variable's semantics aren't preserved through this clone process (though given that what happens to the thing returned by transform is that it gets JSON.stringify'd, maybe this isn't worth stressing about)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions