amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Api Validation does not take into account enum().array() when submiting

Open charlo06 opened this issue 7 months ago • 2 comments

Environment information

System:
  OS: Windows 11 10.0.26100
  CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  Memory: 2.14 GB / 15.80 GB
Binaries:
  Node: 23.6.0 - C:\Program Files\nodejs\node.EXE
  Yarn: undefined - undefined
  npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.6.0
  @aws-amplify/backend: 1.14.1
  @aws-amplify/backend-ai: Not Found
  @aws-amplify/backend-auth: 1.5.0
  @aws-amplify/backend-cli: 1.4.11
  @aws-amplify/backend-data: 1.4.0
  @aws-amplify/backend-deployer: 1.1.18
  @aws-amplify/backend-function: 1.12.2
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.4
  @aws-amplify/backend-secret: 1.1.6
  @aws-amplify/backend-storage: 1.2.4
  @aws-amplify/cli-core: 1.3.0
  @aws-amplify/client-config: 1.5.7
  @aws-amplify/data-construct: 1.15.0
  @aws-amplify/data-schema: 1.19.0
  @aws-amplify/deployed-backend-client: 1.5.1
  @aws-amplify/form-generator: 1.0.4
  @aws-amplify/model-generator: 1.0.12
  @aws-amplify/platform-core: 1.6.3
  @aws-amplify/plugin-types: 1.8.0
  @aws-amplify/sandbox: 1.2.11
  @aws-amplify/schema-generator: 1.2.7
  aws-amplify: 6.13.3
  aws-cdk: 2.1003.0
  aws-cdk-lib: 2.182.0
  typescript: 5.6.3
No AWS environment variables
No CDK environment variables

Data packages

[email protected] C:\Users\charlelie\Documents\GitHub\kiddosManager
+-- @aws-amplify/[email protected]
| `-- @aws-amplify/[email protected]
|   `-- @aws-amplify/[email protected]
`-- @aws-amplify/[email protected]
  `-- @aws-amplify/[email protected]
    `-- @aws-amplify/[email protected]

Description

Hey, so i'm trying to have a list of enum, so here's what i did :

const schema = a.schema({
SpecialAdCategories: a.enum(['NONE', 'EMPLOYMENT', 'HOUSING', 'CREDIT', 'ISSUES_ELECTIONS_POLITICS', 'ONLINE_GAMBLING_AND_GAMING', 'FINANCIAL_PRODUCTS_SERVICES']),
Campaigns: a
    .model({
      name: a.string().required(),
      special_ad_categories: a.ref('SpecialAdCategories').array().required(),
    }),
  createCampaign: a
    .query()
    .arguments({
      name: a.string().required(),
      special_ad_categories: a.ref('SpecialAdCategories').array().required(),
    })
    .returns(a.json())
    .authorization((allow) => allow.authenticated())
    .handler(a.handler.function(createCampaign)),
})
});

But when i try to make a request to the createCampaign lambda that look likes this for example :

 {
    "name": "TEST",
    "special_ad_categories": ["NONE"]
  })

here's the response it's saying :

Validation error of type VariableTypeMismatch: Variable type '[String]!' doesn't match expected type 'SpecialAdCategories' @ 'createCampaign'

And when i try to make a query using the api playground here's what the query that's formed look like :

query MyQuery {
  createCampaign(
    name: ""
    special_ad_categories: HOUSING
  )
}

and not

query MyQuery {
  createCampaign(
    name: ""
    special_ad_categories: [HOUSING]
  )
}

as one might expect. Don't know if i'm doing something wrong or if there really a bug there

charlo06 avatar Mar 13 '25 14:03 charlo06