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(amplify-appsync-simulator): appsync scalars #5705

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

bboure
Copy link
Contributor

@bboure bboure commented Oct 26, 2020

Issue #, if available:
Fixes #5207

Description of changes:

Several issues here.

  1. AWS scalars were not used at all
    AWS scalars were defined, but never injected in the schema. This is now fixed.
    Please let me know if this was intentional (for some reason)

  2. AWSPhone was needs to be instantiated in order to be injected into the schema.
    Instead, the class itself was passed.
    AWSPhone also seems to accept some options for the country. Since this was not used at all until now, I just left the defaults.

  3. AWSJSON
    Finally, this fixes Value returned by amplify-appsync-simulator for AWSJSON fields doesn't match AppSync #5207
    AWSJSON are stringified in AppSync but were returned as objects in the simulator.

According to the doc and the reverse engineering I have been doing, it should act as follow:

As an Input
JSON strings are parsed as values before getting to mapping template. This means:
"{\"Foo\":\"Bar\"}" becomes {Foo: "Bar"} (object, or Map)
"true" (the string) becomes true (the boolean)
"1" (the string) becomes 1 (the integer)
"\"Hello\"" (double quotes are important) becomes the Hello string
etc.

Any array of the above should also work. Example: "[\"Hello\", \"World\"]"

"Hello" is an invalid json representation and fails.
Any non-string value should fail.

As an output
Basically, any output will be encoded as a JSON
{Foo: "Bar"} becomes {"Foo": "Bar"}, and so on... (Basically, the reverse of the above)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #5705 into master will increase coverage by 0.02%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5705      +/-   ##
==========================================
+ Coverage   58.02%   58.04%   +0.02%     
==========================================
  Files         410      410              
  Lines       18769    18780      +11     
  Branches     3556     3753     +197     
==========================================
+ Hits        10890    10901      +11     
+ Misses       7215     7195      -20     
- Partials      664      684      +20     
Impacted Files Coverage Δ
...ages/amplify-appsync-simulator/src/schema/index.ts 19.40% <ø> (ø)
...sync-simulator/src/schema/appsync-scalars/index.ts 40.27% <75.00%> (+10.76%) ⬆️
packages/amplify-util-mock/src/api/api.ts 0.00% <0.00%> (ø)
packages/graphql-mapping-template/src/print.ts 34.65% <0.00%> (ø)
packages/amplify-util-mock/src/storage/storage.ts 0.00% <0.00%> (ø)
...ges/amplify-util-mock/src/CFNParser/stack/index.ts 0.00% <0.00%> (ø)
...es/amplify-util-mock/src/api/resolver-overrides.ts 0.00% <0.00%> (ø)
...es/graphql-transformer-core/src/stripDirectives.ts 35.29% <0.00%> (ø)
.../amplify-cli-core/src/state-manager/pathManager.ts 67.08% <0.00%> (ø)
.../amplify-util-mock/src/utils/lambda/loadMinimal.ts 0.00% <0.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22209c4...f568bb8. Read the comment docs.

@SwaySway SwaySway self-assigned this Oct 28, 2020
Copy link
Contributor

@SwaySway SwaySway left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the contribution!

@edwardfoyle edwardfoyle merged commit edd8e68 into aws-amplify:master Oct 28, 2020
@ElvenMonky
Copy link

@bboure Thanks a lot for figuring this out!

@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Value returned by amplify-appsync-simulator for AWSJSON fields doesn't match AppSync
4 participants