You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function coerceString(inputValue: mixed): string {
if (typeof inputValue !== 'string') {
throw new GraphQLError(
`String cannot represent a non string value: ${inspect(inputValue)}`,
);
}
return inputValue;
}
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: serializeString,
parseValue: coerceString,
parseLiteral(valueNode) {
if (valueNode.kind !== Kind.STRING) {
throw new GraphQLError(
`String cannot represent a non string value: ${print(valueNode)}`,
valueNode,
);
}
return valueNode.value;
},
});
To add more context, @andimarek noticed this while we had a chat about string-based custom scalars. This sub-category of custom scalars is relying on consistent String coercion across implementations. Hence, we should be in line with the JS implementation, although it is a behaviour change.
Activity
bbakerman commentedon Oct 19, 2022
Citation needed
bbakerman commentedon Oct 19, 2022
from graphql-js
bbakerman commentedon Oct 19, 2022
This is a big behaviour change no?
dondonz commentedon Oct 19, 2022
To add more context, @andimarek noticed this while we had a chat about string-based custom scalars. This sub-category of custom scalars is relying on consistent String coercion across implementations. Hence, we should be in line with the JS implementation, although it is a behaviour change.