aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Combination of `queries:null` or `queries:{list:null}` AND @key(...queryField... gives a `Model[Type]FilterInput` does not exist error #5722

Closed dwamianm closed 3 years ago

dwamianm commented 3 years ago

Describe the bug The genesis of the issue is that I want to turn off the list[Type] query so that we can create a custom resolver and prevent a none admin user from listing all the information in the DB.

We would like @key queries from 'queryField to generate but not the autogenerated queries

The bug happens when we combine queries:null or queries:{list:null} with the queryField, the CLI autogenerated the @key query but does not generate the Model[Type]FilterInput which then throws an error that Model[Type]FilterInput doesn't exist.

Amplify CLI Version 4.31.1

To Reproduce

  1. Create a Model
#find companies by name
#find companies by slug
type Company
  #@searchable <-- commented our @searchable for local mocking...STILL ANNOYING
  @model(subscriptions: null, queries:{list:null, get:"getCompany"})
  @key(name: "companyByName", fields: ["name"], queryField: "listCompaniesByName")
  @key(name: "companyBySlug", fields: ["slug"], queryField: "listCompaniesBySlug") {
  id: ID!
  name: String!
  slug: String!
  description: String
  logoUrl: String
  websiteUrl: String
  industry: String
  industryCode: Int
  dateStarted: AWSDate
  stockTicker: String
  private: BoolEnum
  social: SocialTypes
  address: AddressType
  demographics: CompanyDemographicsType
  keywords: [String]
  labels: [String]
}

type SocialTypes {
  facebook: String
  twitter: String
  linkedin: String
  instagram: String
}

type AddressType {
  addressFull: String
  addressStreet: String
  addressStreet2: String
  addressCity: String
  addressState: String
  addressPostalCode: String
  addressCountry: String
  coordinates: Coordinates
}

type CompanyDemographicsType {
  totalEmployees: Int
  annualRevenue: Float
}

type Coordinates {
  lat: Float
  lon: Float
}
  1. Run amplify mock

Mock throws this error

Failed to start API Mock endpoint Error: Unknown type "ModelCompanyFilterInput". Did you mean "ModelOrgFilterInput", "ModelMemberFilterInput", "ModelCompanyConditionInput", "ModelOrgMemberFilterInput", or "ModelIntegrationFilterInput"?

Unknown type "ModelCompanyFilterInput". Did you mean "ModelOrgFilterInput", "ModelMemberFilterInput", "ModelCompanyConditionInput", "ModelOrgMemberFilterInput", or "ModelIntegrationFilterInput"?

which makes sense because the the schema.graphql file generates the @key queries

 listCompaniesByName(name: String, sortDirection: ModelSortDirection, filter: ModelCompanyFilterInput, limit: Int, nextToken: String): ModelCompanyConnection
 listCompaniesBySlug(slug: String, sortDirection: ModelSortDirection, filter: ModelCompanyFilterInput, limit: Int, nextToken: String): ModelCompanyConnection

But doesn't generated the ModelCompanyFilterInput

If you remove the queries:null or queries:{list:null} from the schema file then it will generate ModelCompanyFilterInput which negates the result I am looking for.

Expected behavior queries:{list:null} should not autogenerate the listCompanys query but since we have defined @key(...queryField:.. should generate that query and all the attribute types including Model[Type]FilterInput

Desktop (please complete the following information):

dwamianm commented 3 years ago

@jhockett any update on this issue? Please let me know if you need any additional info

jhockett commented 3 years ago

Hi @dwamianm, I was able to confirm this behavior on 4.32.0. I'm going to mark this as an enhancement because I think this is intentional that setting queries or a subset of queries to null supersedes any @key's.

jhockett commented 3 years ago

Closing this as a duplicate of aws-amplify/amplify-category-api#245. Please follow that issue for updates and a possible workaround @dwamianm.

dwamianm commented 3 years ago

ok thanks @jhockett

github-actions[bot] commented 3 years ago

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.