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
If applicable, what version of Node.js are you using?
No response
Amplify CLI Version
N/A (but problem exists in 2.16.6 of appsync-simulator)
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes
Describe the bug
AppSync at AWS has supported the Long scalar type since at least 2020, even though it does not appear in its official docs.
I have recently had cause to use this due to an Int growing out of range in my project, and found it works fine.
However, appsync-simulator does not support this type, causing local development to crash.
I've found it trivial to add it locally into the appsync codebase, and I've shared my solution here.
Expected behavior
I expect the simulator to try to behave as closely as possible to the production system.
The following schema works on AWS AppSync, and should be supported in the simulator:
type ExampleSchema {
id: Long
}
Reproduction steps
Create a Graphql schema as below
Run the simulator (in my case I'm running via npx serverless offline start --noAuth, which uses appsync-simulator via the serverless-appsync-simulator package)
You will get the error below when it initialises (you don't even need to hit the endpoint)
Schema
type Query {
run(): SampleSchema
}
type SampleSchema {
id: Long
name: String
}
Project Identifier
No response
Log output
The following error is returned in the CLI when the simulator starts up.
Error: Unknown type "Long". Did you mean "Config"?
Unknown type "Long". Did you mean "Config"?
at assertValidSDL (graphql/validation/validate.js:108:11)
at Object.buildASTSchema (graphql/utilities/buildASTSchema.js:71:34)
at generateDefaultSubscriptions (amplify-appsync-simulator/lib/schema/index.js:148:28)
at Object.generateResolvers (amplify-appsync-simulator/lib/schema/index.js:125:32)
at AmplifyAppSyncSimulator.init (amplify-appsync-simulator/lib/index.js:129:37)
....
This is because amplify-appsync-simulator/lib/schema/appsync-scalars/index.js and index.d.ts are missing the Long scalar type.
Additional information
Adding the following fixes it.
appsync-scalars/index.js:
// This adds the Long scalar typevarLong=newgraphql_1.GraphQLScalarType({name: 'Long',description: 'A large 64-bit integer.',serialize: function(value){returnvalue;},parseValue: function(value){returnvalue;},parseLiteral: function(ast){if(ast.kind!==graphql_1.Kind.INT){thrownewgraphql_1.GraphQLError("Can only validate ints as Longs but got a: "+ast.kind);}returnvalue;},});exports.scalars={AWSJSON: AWSJSON,AWSDate: AWSDate,AWSTime: AWSTime,AWSDateTime: AWSDateTime,AWSPhone: newAWSPhone({name: 'AWSPhone',description: 'AWSPhone'}),AWSEmail: AWSEmail,AWSURL: AWSURL,AWSTimestamp: AWSTimestamp,AWSIPAddress: AWSIPAddress,Long: Long,// <--- this exports it};
How did you install the Amplify CLI?
npm, via Serverless Framework
If applicable, what version of Node.js are you using?
No response
Amplify CLI Version
N/A (but problem exists in 2.16.6 of appsync-simulator)
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes
Describe the bug
AppSync at AWS has supported the
Long
scalar type since at least 2020, even though it does not appear in its official docs.I have recently had cause to use this due to an
Int
growing out of range in my project, and found it works fine.However,
appsync-simulator
does not support this type, causing local development to crash.I've found it trivial to add it locally into the appsync codebase, and I've shared my solution here.
Expected behavior
I expect the simulator to try to behave as closely as possible to the production system.
The following schema works on AWS AppSync, and should be supported in the simulator:
Reproduction steps
npx serverless offline start --noAuth
, which usesappsync-simulator
via theserverless-appsync-simulator
package)Schema
Project Identifier
No response
Log output
The following error is returned in the CLI when the simulator starts up.
This is because
amplify-appsync-simulator/lib/schema/appsync-scalars/index.js
andindex.d.ts
are missing theLong
scalar type.Additional information
Adding the following fixes it.
appsync-scalars/index.js
:appsync-scalars/index.d.ts
:This ninja-edit was made in the compiled source to demonstrate how easy it is to fix, and the line within the actual project is here:
https://github.com/aws-amplify/amplify-cli/blob/9ebe9903042e30028c610e4f0641a9d9ebf8dfb9/packages/amplify-appsync-simulator/src/schema/appsync-scalars/index.ts#L224
Before submitting, please confirm:
The text was updated successfully, but these errors were encountered: