aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
87 stars 75 forks source link

Mixed data-sources (@model as primary and @sql as secondary) #2182

Open toddaa opened 8 months ago

toddaa commented 8 months ago

Describe the feature you'd like to request

I'd like to request the ability to have mixed @model & @sql directives. @model being primary and @sql being secondary. For example:

type Location {
  id: Int
  name: String
}

type User
  @model {
    id: ID!
    user: String! 
    locations: [Location] @sql(reference: "getLocations")
}

Currently, Amplify is returning @sql directive can only be used on Query or Mutation types

Describe the solution you'd like

I'd like to be able to use the @sql directive within the @model directive just like my example showed. Data doesn't need to be intermingled except when the query returns to the client.

Describe alternatives you've considered

the @sql directive generates Lambda functions. I can currently achieve my goal using the @function directive, but I have to manage the Lambda manually whereas with @sql the function is generated automatically within the CDK construct code. I simply supply the query and access credentials via SSM as instructed here: https://docs.amplify.aws/javascript/build-a-backend/graphqlapi/connect-api-to-existing-database/

Additional context

2175 is a very close and possible replication of this request. Might be different enough though for this one to be a valid request. I'll follow them both just in case.

Is this something that you'd be interested in working on?

Would this feature include a breaking change?

AnilMaktala commented 8 months ago

Hi @toddaa, Thank you for raising this. Marking this as a feature request for the team to evaluate further.