Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw TypeError when coercing an array into a GraphQLString #925

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

robzhu
Copy link
Contributor

@robzhu robzhu commented Jun 21, 2017

Previously, we were using the default JS logic to coerce arrays to strings. This PR detects and disallows conversion of arrays into strings.

#771

}
return String(value);
}

export const GraphQLString = new GraphQLScalarType({
name: 'String',
description:
'The `String` scalar type represents textual data, represented as UTF-8 ' +
'character sequences. The String type is most often used by GraphQL to ' +
'represent free-form human-readable text.',
serialize: String,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewer: thoughts on updating the serialize behavior as well? See coerceFloat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I think this change is actually more compelling for serializing than parsing input values.

@leebyron leebyron merged commit 24a5038 into master Aug 14, 2017
@leebyron leebyron deleted the input-validation-string-array branch December 6, 2017 22:11
IvanGoncharov added a commit that referenced this pull request Jun 1, 2018
Working on #1333 I noticed that you can pass arrays as scalars in a query variable, e.g. [SWAPI example](http://graphql.org/swapi-graphql/?query=query%20(%24id%3A%20ID)%20%7B%0A%20%20person(personID%3A%20%24id)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D&variables=%7B%0A%20%20%22id%22%3A%20%5B1%5D%0A%7D)
This PR is based on #925 but fixing same issue for types other than `String` e.g.
```js
Number([1]) // 1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants