-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Convert arbitrary scalar values into ASTs and back #1817
Comments
@IvanGoncharov FYI |
@anhldbk Thanks for detail report. graphql-js/src/utilities/isValidJSValue.js Lines 14 to 22 in b8a0f3b
It's a little bit more complex, correct AST node for object value should contain graphql-js/src/language/ast.js Lines 346 to 350 in b8a0f3b
I think correct solution would be introduce |
@IvanGoncharov So when users define a custom scalar, they must provide a function named |
@anhldbk It's designed proposal for a fix. Idea is to have optional |
I think this is a better fix: if (typeof serialized === 'object') {
if (Array.isArray(serialized)) {
return {
kind: Kind.LIST,
values: serialized.map(v => astFromValue(v, type)),
};
}
return {
kind: Kind.OBJECT,
fields: Object.entries(serialized).map(([k, v]) => {
return {
kind: 'ObjectField',
name: { kind: 'Name', value: k },
value: astFromValue(v, type),
};
}),
};
} I think we can keep Enum and GraphQLID logic in this function and move all the stuff regarding scalars (boolean, string, number and this fix also) to @IvanGoncharov Do you want me to make PR for these changes? |
just fyi: GraphQL Java will add a very similar method to the proposed |
This should be fixed by introduction of |
Reporting issues with GraphQL.js
This issue is related to: #1815
Expected:
Code:
Result
Solution
I have to patch
astFromValue
: https://github.com/graphql/graphql-js/blob/8aef229cb2/src/utilities/astFromValue.js#L139-L140 by adding following lines before L139Question
The solution above may not be adequate. Would you please tell me it's worth to make a RP against this issue and how to properly resolve it?
The text was updated successfully, but these errors were encountered: