Amplify-cli: Adding lambda resolver results in "TypeError: Must Provide Source" when running query

Created on 7 Oct 2020  路  8Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
Having worked on a project for a while, the ability to add new lambda resolvers is suddenly broken.

I add the lambda as follows:

amplify add function                                                                         
? Select which capability you want to add: Lambda function (serverless function)
? Provide a friendly name for your resource to be used as a label for this category in the project: moo
? Provide the AWS Lambda function name: moo
? Choose the runtime that you want to use: Python
Only one template found - using Hello World by default.
? Do you want to access other resources in this project from your Lambda function? No
? Do you want to invoke this function on a recurring schedule? No
? Do you want to configure Lambda layers for this function? No
? Do you want to edit the local lambda function now? Yes
Please edit the file in your editor: /Users/halfdan/vuzz/repos/yoor/app/amplify/backend/function/moo/src/index.py
? Press enter to continue
Successfully added resource moo locally.

Next steps:
Check out sample function code generated in <project-dir>/amplify/backend/function/moo/src
"amplify function build" builds all of your functions currently in the project
"amplify mock function <functionName>" runs your function locally
"amplify push" builds all of your local backend resources and provisions them in the cloud
"amplify publish" builds all of your local backend and front-end resources (if you added hosting category) and provisions them in the cloud

and adds the query to the gql schema:

type Query {
  echo(msg: String): String @function(name: "yoorecho-${env}")
  foo(msg: String): String @function(name: "yoorecho-${env}")
  bar(msg: String): String @function(name: "yoorbar-${env}")
  moo(msg: String): String @function(name: "yoormoo-${env}")
}

then run amplify push

When I then run the query moo in my app, the following error happens:

ERROR TypeError: Must provide Source. Received: undefined
    at parse (parser.mjs:27)
    at GraphQLAPIClass.graphql (GraphQLAPI.ts:191)
    at APIClass.graphql (API.ts:194)
    at fetchUser (index.tsx:56)
    at index.tsx:73
    at commitHookEffectListMount (react-dom.development.js:19731)
    at commitPassiveHookEffects (react-dom.development.js:19769)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at flushPassiveEffectsImpl (react-dom.development.js:22853)
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushPassiveEffects (react-dom.development.js:22820)
    at performSyncWorkOnRoot (react-dom.development.js:21737)
    at react-dom.development.js:11089
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
    at flushSyncCallbackQueue (react-dom.development.js:11072)
    at scheduleUpdateOnFiber (react-dom.development.js:21199)
    at dispatchAction (react-dom.development.js:15660)
    at withAuthenticator.tsx:42
    at step (index.tsx:29)
    at Object.next (index.tsx:29)
    at fulfilled (index.tsx:29)

Note that echo, foo and bar queries, backed by lambda resolvers added earlier, all work fine!

amplify mock function moo works fine.

The only big change I did recently was to add a new env. I can't say if that's what messed things up though.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
The query to execute

Code Snippet
Please provide a code snippet or a link to sample code of the issue you are experiencing to help us reproduce the issue. (Be sure to remove any sensitive data)

Screenshots
If applicable, add screenshots to help explain your problem.

What is Configured?
If applicable, please provide what is configured for Amplify CLI:

  • Which steps did you follow via Amplify CLI when configuring your resources.
  • Which resources do you have configured?

    • If applicable, please provide your aws-exports file:

aws-exports:

const awsmobile = {
    "aws_project_region": "ap-northeast-1",
    "aws_cognito_identity_pool_id": "ap-northeast-1:69ff8753-e532-4601-826f-948369fca16b",
    "aws_cognito_region": "ap-northeast-1",
    "aws_user_pools_id": "ap-northeast-1_TUy2VI5Jl",
    "aws_user_pools_web_client_id": "2rkdeu4l58djdf7echpp1a5t0e",
    "oauth": {
        "domain": "seesaayoorapp78701dff-78701dff-hdev.auth.ap-northeast-1.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "http://localhost:3000/",
        "redirectSignOut": "http://localhost:3000/",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "aws_appsync_graphqlEndpoint": "https://pfehe4a4rvbhlpqynk4476heam.appsync-api.ap-northeast-1.amazonaws.com/graphql",
    "aws_appsync_region": "ap-northeast-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS"
};
  • If applicable, provide more configuration data, for example for Amazon Cognito, run aws cognito-idp describe-user-pool --user-pool-id us-west-2_xxxxxx (Be sure to remove any sensitive data)


Environment

npx: installed 1 in 1.314s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 349.95 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.0 - /usr/local/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 86.0.4240.75
    Firefox: 81.0
    Safari: 13.1.2
  npmPackages:
    @aws-amplify/ui-react: ^0.2.18 => 0.2.18
    @material-ui/core: ^4.11.0 => 4.11.0
    @material-ui/icons: ^4.9.1 => 4.9.1
    @testing-library/jest-dom: ^4.2.4 => 4.2.4
    @testing-library/react: ^9.5.0 => 9.5.0
    @testing-library/user-event: ^7.2.1 => 7.2.1
    @types/jest: ^24.9.1 => 24.9.1
    @types/node: ^12.12.55 => 12.12.55
    @types/react: ^16.9.49 => 16.9.49
    @types/react-dom: ^16.9.8 => 16.9.8
    @types/react-router-dom: ^5.1.5 => 5.1.5
    @types/react-router-hash-link: ^1.2.1 => 1.2.1
    aws-amplify: ^3.1.1 => 3.1.1
    faker: ^5.1.0 => 5.1.0
    md5: ^2.3.0 => 2.3.0
    react: ^16.13.1 => 16.13.1
    react-dom: ^16.13.1 => 16.13.1
    react-router-dom: ^5.2.0 => 5.2.0
    react-router-hash-link: ^2.1.0 => 2.1.0
    react-scripts: 3.4.3 => 3.4.3
    typescript: ^3.9.7 => 3.9.7
  npmGlobalPackages:
    @aws-amplify/cli: 4.27.3
    md5: 2.2.1
    n: 6.7.0
    npm-upgrade: 2.0.4
    npm: 6.13.4
    ts-node: 8.10.2
    typescript: 3.8.2

Additional context
Add any other context about the problem here.

_You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app._

api-graphql pending-triage

Most helpful comment

This looks like an issue with the library. @ashika01 could you investigate further why this error gets thrown

All 8 comments

@halfdanrump What response do you get when you run it in the Appsync console?

@ammarkarachi Ah yes, I should have provided that detail as well.

When I run the query from the AppSync console it triggers the lambda and returns the expected result.

This looks like an issue with the library. @ashika01 could you investigate further why this error gets thrown

@ashika01 Let me know if you need help reproducing the issue. We can meet on discord and I can show you what I do.

@halfdanrump Someone from the team would look into this.

I tried cloning my repo and pulling the amplify project. Now moo worked!

In my old repo pulling the amplify project again didn't fix the problem. I also tried deleting #current-cloud-backend and then pull again, but it still didn't fix the problem.

I hope this is a hint.

Thanks for reporting this @halfdanrump, this is related to Amplify CLI. Transferring this issue to the Amplify CLI team. @yuth can you weigh in on this being a library issue?

@sammartinez Seems like the issue is on the frontend app instead of the backend setup, if the queries can be run successfully on the AppSync console, that means they are correctly set up.

Was this page helpful?
0 / 5 - 0 ratings