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

Get type mismatch when using array of dynamic groups in @auth rules #5300

Closed
hhemmati81 opened this issue Sep 10, 2020 · 5 comments
Closed

Comments

@hhemmati81
Copy link

I am trying to use an array of dynamic groups in the @auth rules and I get type mismatch error. It works in the mock just fine though. It also works if I use a single group instead of an array. Here are my schema and the error message that I am getting.

type ViralLoad
@model
@key(
  name: "ByDate"
  fields: ["groups", "createdAt"]
  queryField: "viralLoadByGroup"
)
@auth(
  rules: [
    { allow: owner }
    { allow: groups, groupsField: "groups", operations: [read] }
  ]
) {
  id: ID!
  location: String!
  createdAt: AWSDateTime
  time: [ViralLoadTime]
  reagentKitID: String
  machineID: String
  samples: [ViralSample]
  groups: [String]
}

type ViralLoadTime {
  start: AWSDateTime
  stop: AWSDateTime
  experimental: AWSDateTime
}

type ViralSample {
  load: Int
  control: Int
}

My sample mutation.

mutation MyMutation {
  createViralLoad(input: {location: "Location 1", createdAt: "2020-09-09T00:00:00Z", groups: ["Admin"]}) {
    location
    createdAt
  }
}

And the error message.

{
  "data": {
    "createViralLoad": null
  },
  "errors": [
    {
      "path": [
        "createViralLoad"
      ],
      "data": null,
      "errorType": "DynamoDB:DynamoDbException",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "One or more parameter values were invalid: Type mismatch for Index Key groups Expected: S Actual: L IndexName: ByDate (Service: DynamoDb, Status Code: 400, Request ID: QRGBTDVJ7EDIJV0JBK4JCJCDHRVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)"
    }
  ]
}
@ashika01 ashika01 transferred this issue from aws-amplify/amplify-js Sep 10, 2020
@RossWilliams
Copy link

The "byDate" GSI uses groups as part of the key. Keys can only be string, number, or binary types. They cannot be lists.

@hhemmati81
Copy link
Author

So the problem is in the key section not actually using an array for the auth. I wonder why this is working in the amplify mock.

@RossWilliams
Copy link

The problem is even earlier. There is a bug in the @key transformer code that validates the schema. It incorrectly tests for scalar types. It calls a method to get the field type, but that method looks inside lists and reports on the type of the list, so it never detects an invalid list type. See here

@hhemmati81
Copy link
Author

Thanks Ross, this was driving me crazy. At least I know what I have to do to get it working.

RossWilliams pushed a commit to RossWilliams/amplify-cli that referenced this issue Sep 12, 2020
resolves aws-amplify#5300

Logic for 'isScalar' treated lists as scalar types. This allowed indexes to be created with invalid key types.

This modifies the isScalar function to return false for list types, and updates other areas as needed with a new 'isScalarOrScalarList' function

Includes new test which fails without this fix.
Fixes adjacent tests failing because of missing model transforms, and not for the stated reason.
RossWilliams pushed a commit to RossWilliams/amplify-cli that referenced this issue Sep 12, 2020
resolves aws-amplify#5300

Logic for 'isScalar' treated lists as scalar types. This allowed indexes to be created with invalid key types.

This modifies the isScalar function to return false for list types, and updates other areas as needed with a new 'isScalarOrScalarList' function

Includes new test which fails without this fix.
Fixes adjacent tests failing because of missing model transforms, and not for the stated reason.
RossWilliams pushed a commit to RossWilliams/amplify-cli that referenced this issue Oct 18, 2020
resolves aws-amplify#5300

Logic for 'isScalar' treated lists as scalar types. This allowed indexes to be created with invalid key types.

This modifies the isScalar function to return false for list types, and updates other areas as needed with a new 'isScalarOrScalarList' function

Includes new test which fails without this fix.
Fixes adjacent tests failing because of missing model transforms, and not for the stated reason.
SwaySway pushed a commit that referenced this issue Dec 11, 2020
* fix(graphql-key-transformer): prevent non-scalar key fields

resolves #5300

Logic for 'isScalar' treated lists as scalar types. This allowed indexes to be created with invalid key types.

This modifies the isScalar function to return false for list types, and updates other areas as needed with a new 'isScalarOrScalarList' function

Includes new test which fails without this fix.
Fixes adjacent tests failing because of missing model transforms, and not for the stated reason.

* fix: schema generation for list input types
@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators May 25, 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

No branches or pull requests

2 participants