amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Validation error of type VariableTypeMismatch: Variable type 'String' doesn't match expected type 'String!'

Open josh-tncarry opened this issue 6 years ago • 6 comments

Describe the bug When building my project using the CLI version 4.21.4 there are breaking changes introduced into the compiled GraphQL schema. Parameters to queries based on a GSI that were previously not designated as required ! are now designated as required.

While the auto-generated queries will be updated, this will cause any user generated queries to fail if they are not updated.

Amplify CLI Version 4.21.4

To Reproduce Create a simple @model in the graphql schema file with an additional @key with a specified top level query.

type Quiz
  @model
  @key(
    name: "ByCourseId"
    fields: ["courseId"]
    queryField: "quizesByCourseId"
  ) {
  id: ID!
  courseId: ID
}

Run the amplify api gql-compile && amplify codegen commands

Using the CLI version <= 4.21.3 will produce a compiled graphql query that looks like this:

quizesByCourseId(courseId: ID, ...

And a autogenerated query that looks like this:

export const quizesByCourseId = /* GraphQL */ `
  query QuizesByCourseId(
    $courseId: ID

Whereas using the CLI version 4.21.4 will produce a compiled graphql query that looks like this:

quizesByCourseId(courseId: ID!, ...

And an autogenerated query that looks like this:

export const quizesByCourseId = /* GraphQL */ `
  query QuizesByCourseId(
    $courseId: ID!

Expected behavior While this may in fact be the "correct" way to compile this, it is a breaking change. If someone were to deploy this to a shared backend without also updating the corresponding queries the impact to production could be pretty severe.

This is not a patch fix, or even a minor update, but a change that will result in breakages. People will need to appropriately plan for an update like this to ensure it does not cause problems.

Desktop (please complete the following information):

  • Irrelevant. This is behavior intrinsic to the CLI and not dependent on OS.

Additional context I found out about this because I have my Amplify Console set to use the latest CLI. The front-end compilation failed, but the back-end had already been deployed causing previously working queries to start failing.

josh-tncarry avatar Jun 19 '20 15:06 josh-tncarry

Same problem here

egyangel avatar Jun 19 '20 17:06 egyangel

@josh-tncarry @egyangel we had fixes around @key that made it constrained as in your @key definition courseId is the partition key, hence it is mandatory.

I'm taking it to the team for triage to get the best way to resolve it.

attilah avatar Jun 20 '20 00:06 attilah

Same issue, has broken the API for me

dasearle avatar Jun 21 '20 09:06 dasearle

Same issue here, any updates? Thanks.

jane-clickfrenzy avatar Jun 23 '20 01:06 jane-clickfrenzy

Closing this issue as we have deprecated version 4.21.4 due issues with @key. Should you experience any issues related to this in the latest version, as of now v4.25.0, please comment below.

SwaySway avatar Jul 29 '20 02:07 SwaySway

This issue 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[bot] avatar May 26 '21 01:05 github-actions[bot]