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

fix(playground): return the string of NaN and Infinity in the playground #505

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

YonatanKra
Copy link
Collaborator

Closes #367
See my comment in #367 regarding Infinity and NaN in JSON

@YonatanKra YonatanKra changed the title Return the string of NaN and Infinity in the playground fix(playground): return the string of NaN and Infinity in the playground Oct 9, 2020
@mhagmajer
Copy link
Collaborator

@YonatanKra thanks for creating another PR 💪

Can you explain your rationale of fixing this and how this PR was tested? As you have noticed in #367 (comment) neither Infinity nor NaN can be transferred in JSON and playground is based on sending an AskQL query and receiving a JSON response so I'm not sure how this can be solved without challenging that assumption.

@YonatanKra
Copy link
Collaborator Author

@YonatanKra thanks for creating another PR 💪

Can you explain your rationale of fixing this and how this PR was tested? As you have noticed in #367 (comment) neither Infinity nor NaN can be transferred in JSON and playground is based on sending an AskQL query and receiving a JSON response so I'm not sure how this can be solved without challenging that assumption.

What I did was change how the playground works. It returns a string of Infinity or NaN in case these values are returned (instead of returning a json.stringifyof them.

Tested on local playground

Comment on lines +30 to +49
export async function compileAskCode(
baseEnvironment: {
values?: { [p: string]: any };
customValues?: { [p: string]: any };
resources: {
[p: string]: Resource<any, any>;
};
},
askCode: AskCodeOrValue
) {
let result = await runUntyped(baseEnvironment, askCode, []);
if (
result === Infinity ||
result === -Infinity ||
(typeof result === 'number' && isNaN(result))
) {
result = result.toString();
}
return result;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mhagmajer this is the "magic". Would it be valid to add this logic to the middleware as well?

Copy link
Collaborator

@mhagmajer mhagmajer left a comment

Choose a reason for hiding this comment

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

Let's wait for discussion at #367 (comment) to resolve

@czerwinskilukasz1
Copy link
Collaborator

@YonatanKra , I believe we should first finish our discussion in #367 and only after that create any PRs.
For now I would pause this PR until we come up to a conclusion how to solve it.

@YonatanKra YonatanKra marked this pull request as draft October 16, 2020 13:37
@YonatanKra
Copy link
Collaborator Author

@YonatanKra , I believe we should first finish our discussion in #367 and only after that create any PRs.
For now I would pause this PR until we come up to a conclusion how to solve it.

Drafted :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[playground] Infinity is reported as null
3 participants