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 73 forks source link

Unable to override an autogenerated pipeline resolver #2692

Open jguipi opened 1 month ago

jguipi commented 1 month ago

How did you install the Amplify CLI?

npm install -g @aws-amplify/cli

If applicable, what version of Node.js are you using?

v22.2.0

Amplify CLI Version

12.12.4

What operating system are you using?

mac os 14.5 (23F79)

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

no manual change were made

Describe the bug

This schema is generating an autogenerated pipeline resolver that I'm unable to override using the amplify/backend/api/myapi/override.ts

schema.graphql

type User
  @model() {
  id: ID!
  firstname: String!
  lastname: String
  Children: [Child]
    @hasMany(indexName: "byUser", fields: ["id"])
}

type Child
  @model() {
  id: ID!
  firstname: String!
  lastname: String!
  userID: ID
    @index(name: "byUser")
  User: User
}

It seems like the key User.Children autogenerate, a resolver that I'm unable to override.

Override.ts

  const getChild = resources.models['Child'];
  const getChild2 = resources.models['User'];

  console.log(getChild)
  const getChildResolvers =
    getChild.resolvers['queryGetChildResolver'].pipelineConfig['functions'];
  getChild.resolvers['queryGetChildResolver'].pipelineConfig = {
    functions: [
      function_1,
      function_2,
      function_3,
      ...getChildResolvers,
    ],
  };

When I log the following, I'm unable to see the autogenerated pipeline resolver in the data structure:

const getChild = resources.models['Child'];
or 
const getChild = resources.models['User'];

On the other hand, when I look at the AWS UI I'm able to see the autogenerated function

Captura de pantalla 2024-07-05 a la(s) 10 43 51 a m Captura de pantalla 2024-07-05 a la(s) 10 43 56 a m
image image

Expected behavior

Being able to override the pipeline resolver that was automatically generated by amplify

Reproduction steps

  1. Add this schema
  2. Push it to amplify
  3. Create an override.ts file and try to override the autogenerated function

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

ykethan commented 1 month ago

Hey @jguipi, 👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂. But refer to https://docs.amplify.aws/gen1/react/build-a-backend/graphqlapi/custom-business-logic/#override-amplify-generated-resolvers providing information on overriding Amplify generated resolvers.

jguipi commented 1 month ago

As extra detail, I already copied the autogenerated resolver into the right path

From: amplify/backend/api/DevApi/build/resolvers To : amplify/backend/api/DevApi/build/tsconfig.resource.json

image

Is it normal that the file that were autogenerated are not following the naming convention mentioned here. The current files name are presented in the screenshot

AnilMaktala commented 1 month ago

Hi @jguipi, Thanks for bringing this up. To override the resolvers, you need to copy the autogenerated resolver from amplify/backend/api/<resource_name>/build/resolvers/ to amplify/backend/api/<resource_name>/resolvers/. The naming convention in the screenshot is expected for relationship tables. Please let us know if you still encounter any issues.

jguipi commented 1 month ago

Hi @jguipi, Thanks for bringing this up. To override the resolvers, you need to copy the autogenerated resolver from amplify/backend/api/<resource_name>/build/resolvers/ to amplify/backend/api/<resource_name>/resolvers/. The naming convention in the screenshot is expected for relationship tables. Please let us know if you still encounter any issues.

That was already done, but when I try to add the code in the override.ts to override the pipeline resolver that fonction is not there.

As shown above, I was not able to found the function in either of those model:

const getChildModel= resources.models['Child'];
const getUserModel = resources.models['User'];

console.log(getChildModel)
console.log(getUserModel)

getChildModel return

image

getUserModel return

image

There is no mention of that autogenerated function

AnilMaktala commented 1 month ago

Hi @jguipi, Could we arrange a call to explore this issue in detail?

AnilMaktala commented 4 weeks ago

Hey @jguipi, Are you still experiencing this issue?

jguipi commented 3 weeks ago

Hi @jguipi, Could we arrange a call to explore this issue in detail?

Hi ! That would be great since I’m still facing the same issue.

sorry I’m currently on vacation and I don’t have my laptop. Can we have a call when I come back ? After August 10th.

jguipi commented 1 week ago

Let me know when you're available. I'm free from 3 PM Montreal time almost every day. (7 PM UTC)

https://juwrl.setmore.com/j

AnilMaktala commented 1 week ago

Hey @jguipi , Are you on Discord? If so, could you please share your Discord username with me?

jguipi commented 4 days ago

Hey @jguipi , Are you on Discord? If so, could you please share your Discord username with me?

Sure

discord: j.g7636

AnilMaktala commented 2 days ago

@jguipi Thanks for sharing your username. I’ll connect with you on Discord.