Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running amplify codegen add #50

Closed
dabit3 opened this issue Aug 27, 2018 · 10 comments · Fixed by #66
Closed

Error when running amplify codegen add #50

dabit3 opened this issue Aug 27, 2018 · 10 comments · Fixed by #66
Assignees

Comments

@dabit3
Copy link
Contributor

dabit3 commented Aug 27, 2018

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Error is thrown:

? Enter the file name pattern of graphql queries, mutation and subscriptions graphql/**/*.graphql
? Choose the code generation language target typescript
? Enter the file name for the generated code API.ts
? Do you want to generate code Yes
✔ Downloaded the schema
✔ code generated successfully and saved in file API.ts
⠧ Downloading the introspection schemavvv -----[ DEBUG ]----- vvv
{ NotFoundException: GraphQL API clpp5lckabgz7pg3vgkfmen5r4 not found.
    at Object.extractError (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.extractError (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
    at Request.callListeners (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:685:12)
  message: 'GraphQL API clpp5lckabgz7pg3vgkfmen5r4 not found.',
  code: 'NotFoundException',
  time: 2018-08-27T21:25:44.399Z,
  requestId: 'c18e25cd-aa3f-11e8-a748-97f03f6dd468',
  statusCode: 404,
  retryable: false,
  retryDelay: 80.31176542355047 }
^^^ -----[ DEBUG ]----- ^^^
2018-08-27T21:25:44.410Z - error: uncaughtException: Argument "data" passed to write(path, data, [options]) must be a string or a buffer or an object or an array. Received undefined date=Mon Aug 27 2018 14:25:44 GMT-0700 (PDT), pid=65821, uid=1070061038, gid=1896053708, cwd=/Users/dabit/temp/delete/NewAmplifyRNApp, execPath=/Users/dabit/.nvm/versions/node/v9.4.0/bin/node, version=v9.4.0, argv=[/Users/dabit/.nvm/versions/node/v9.4.0/bin/node, /Users/dabit/.nvm/versions/node/v9.4.0/bin/amplify, codegen, add], rss=129445888, heapTotal=102473728, heapUsed=66811272, external=937194, loadavg=[2.8505859375, 2.796875, 3.25048828125], uptime=340092, trace=[column=11, file=/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/utils/validate.js, function=Object.validateArgument [as argument], line=109, method=validateArgument [as argument], native=false, column=12, file=/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/write.js, function=Object.validateInput, line=11, method=validateInput, native=false, column=13, file=/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/jetpack.js, function=Object.write, line=225, method=write, native=false, column=11, file=/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/utils/downloadIntrospectionSchema.js, function=downloadIntrospectionSchema, line=16, method=null, native=false, column=null, file=null, function=null, line=null, method=null, native=false, column=7, file=internal/process/next_tick.js, function=process._tickCallback, line=160, method=_tickCallback, native=false], stack=[Error: Argument "data" passed to write(path, data, [options]) must be a string or a buffer or an object or an array. Received undefined,     at Object.validateArgument [as argument] (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/utils/validate.js:109:11),     at Object.validateInput (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/write.js:11:12),     at Object.write (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/fs-jetpack/lib/jetpack.js:225:13),     at downloadIntrospectionSchema (/Users/dabit/.nvm/versions/node/v9.4.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-codegen/src/utils/downloadIntrospectionSchema.js:16:11),     at <anonymous>,     at process._tickCallback (internal/process/next_tick.js:160:7)]

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Steps to reproduce the issue:

  1. Create Amplify project
  2. Add GraphQL API using Amplify CLI
  3. Create the following queries & mutations:
// graphql/mutations/createPerson.graphql
mutation createPerson($name: String!, $age: Int, $description: String) {
  createPerson(input: {
    name: $name
    age: $age
    description: $description
  }) {
    id
    name
    age
    description
  }
}

// graphql/queries/listPeople.graphql
query listPeople {
  listPersons {
    items {
      id
      name
      description
    }
  }
}
  1. Run amplify codegen add

What is the expected behavior?
Typed API.ts is created with no error

What is actual behavior?
Typed API.ts file gets created with the following (but above error is thrown):

/* tslint:disable */
//  This file was automatically generated and should not be edited.

export type createPersonMutationVariables = {
  name: string,
  age?: number | null,
  description?: string | null,
};

export type createPersonMutation = {
  createPerson:  {
    __typename: "Person",
    id: string,
    name: string,
    age: number | null,
    description: string | null,
  } | null,
};

export type listPeopleQuery = {
  listPersons:  {
    __typename: "ModelPersonConnection",
    items:  Array< {
      __typename: "Person",
      id: string,
      name: string,
      description: string | null,
    } | null > | null,
  } | null,
};

Additional environment details

  • OS version (ie Windows 10 build X, macOS Sierra 10.12.6, etc.)
    Mac OS Sierra 10.12.6
  • Output of amplify --version:
    0.1.14
  • Did this work in previous versions?: Y/N
    Not sure
@dabit3
Copy link
Contributor Author

dabit3 commented Aug 27, 2018

Another note, this is after creating & deleting another GraphQL API using the Amplify CLI.

I.e. I created an API, removed it using amplify remove api, then added another API. Just in case this could be part of the cause of the issue. In fact, let me recreate this from scratch in a new project & see if I can reproduce.

@kaustavghosh06
Copy link
Contributor

Did you push the new API to the cloud?

@dabit3
Copy link
Contributor Author

dabit3 commented Aug 27, 2018

@kaustavghosh06 yes, this was after pushing & creating the API.

Also, I just tried on a brand new API & had the same failure so it wasn't any previous configuration that was causing the issue.

@kaustavghosh06
Copy link
Contributor

@dabit3 Thanks for the info. @yuth is looking into this issue.

@yuth
Copy link
Contributor

yuth commented Aug 27, 2018

@dabit3 Does API.ts have any content in it. From the stack it looks like downloading introspection schema failed.

@kaustavghosh06
Copy link
Contributor

@dabit3 I couldn't reproduce the issue after initializing a new project. Here's my flow and please let me know if you did anything different.

f45c89966b0d:amptest kaustavg$ amplify api add
? Please select from one of the below mentioned services GraphQL
? Provide API name: amptest
? Choose an authorization type for the API API key
? Do you have an annotated GraphQL schema? No
? Do you want a guided schema creation? true
? What best describes your project: (Use arrow keys)
? What best describes your project: Single object with fields (e.g., “Todo” with
 ID, name, description)
? Do you want to edit the schema now? (Y/n) n
? Do you want to edit the schema now? No

GraphQL schema compiled successfully. Edit your schema at /Users/kaustavg/amptest/amplify/backend/api/amptest/schema.graphql
Successfully added resource amptest locally

Some next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud

f45c89966b0d:amptest kaustavg$ amplify push
| Category | Resource name | Operation | Provider plugin   |
| -------- | ------------- | --------- | ----------------- |
| Api      | amptest       | Create    | awscloudformation |
? Are you sure you want to continue? true
⠋ Updating resources in the cloud. This may take a few minutes...
GraphQL schema compiled successfully. Edit your schema at /Users/kaustavg/amptest/amplify/backend/api/amptest/schema.graphql
⠙ Updating resources in the cloud. This may take a few minutes...

UPDATE_IN_PROGRESS amptest-20180827155531 AWS::CloudFormation::Stack Mon Aug 27 2018 16:38:52 GMT-0700 (PDT) User Initiated             
CREATE_IN_PROGRESS apiamptest             AWS::CloudFormation::Stack Mon Aug 27 2018 16:39:00 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS apiamptest             AWS::CloudFormation::Stack Mon Aug 27 2018 16:39:01 GMT-0700 (PDT) Resource creation Initiated
⠦ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS amptest-20180827155531-apiamptest-2ZLVICBIDXT2 AWS::CloudFormation::Stack Mon Aug 27 2018 16:39:01 GMT-0700 (PDT) User Initiated
⠴ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS GraphQLAPI    AWS::AppSync::GraphQLApi    Mon Aug 27 2018 16:39:06 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS GraphQLAPI    AWS::AppSync::GraphQLApi    Mon Aug 27 2018 16:39:08 GMT-0700 (PDT) Resource creation Initiated
CREATE_COMPLETE    GraphQLAPI    AWS::AppSync::GraphQLApi    Mon Aug 27 2018 16:39:09 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS GraphQLSchema AWS::AppSync::GraphQLSchema Mon Aug 27 2018 16:39:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS TodoTable     AWS::DynamoDB::Table        Mon Aug 27 2018 16:39:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS GraphQLAPIKey AWS::AppSync::ApiKey        Mon Aug 27 2018 16:39:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS TodoTable     AWS::DynamoDB::Table        Mon Aug 27 2018 16:39:12 GMT-0700 (PDT) Resource creation Initiated
⠴ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS GraphQLAPIKey AWS::AppSync::ApiKey        Mon Aug 27 2018 16:39:13 GMT-0700 (PDT) Resource creation Initiated
CREATE_IN_PROGRESS GraphQLSchema AWS::AppSync::GraphQLSchema Mon Aug 27 2018 16:39:14 GMT-0700 (PDT) Resource creation Initiated
CREATE_COMPLETE    GraphQLAPIKey AWS::AppSync::ApiKey        Mon Aug 27 2018 16:39:14 GMT-0700 (PDT)                            
⠴ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE GraphQLSchema AWS::AppSync::GraphQLSchema Mon Aug 27 2018 16:39:26 GMT-0700 (PDT) 
⠴ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE    TodoTable   AWS::DynamoDB::Table Mon Aug 27 2018 16:39:43 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS TodoIAMRole AWS::IAM::Role       Mon Aug 27 2018 16:39:46 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS TodoIAMRole AWS::IAM::Role       Mon Aug 27 2018 16:39:46 GMT-0700 (PDT) Resource creation Initiated
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE    TodoIAMRole    AWS::IAM::Role           Mon Aug 27 2018 16:39:59 GMT-0700 (PDT) 
CREATE_IN_PROGRESS TodoDataSource AWS::AppSync::DataSource Mon Aug 27 2018 16:40:02 GMT-0700 (PDT) 
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS GetTodoResolver    AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:10 GMT-0700 (PDT) Resource creation Initiated
CREATE_IN_PROGRESS TodoDataSource     AWS::AppSync::DataSource Mon Aug 27 2018 16:40:04 GMT-0700 (PDT) Resource creation Initiated
CREATE_IN_PROGRESS CreateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:10 GMT-0700 (PDT) Resource creation Initiated
CREATE_COMPLETE    CreateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS DeleteTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT) Resource creation Initiated
CREATE_COMPLETE    GetTodoResolver    AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS UpdateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:10 GMT-0700 (PDT) Resource creation Initiated
CREATE_IN_PROGRESS ListTodoResolver   AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:10 GMT-0700 (PDT) Resource creation Initiated
CREATE_COMPLETE    TodoDataSource     AWS::AppSync::DataSource Mon Aug 27 2018 16:40:05 GMT-0700 (PDT)                            
CREATE_COMPLETE    ListTodoResolver   AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS ListTodoResolver   AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:08 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS GetTodoResolver    AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:08 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS UpdateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:08 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS DeleteTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:08 GMT-0700 (PDT)                            
CREATE_IN_PROGRESS CreateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:07 GMT-0700 (PDT)                            
CREATE_COMPLETE    UpdateTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT)                            
CREATE_COMPLETE    DeleteTodoResolver AWS::AppSync::Resolver   Mon Aug 27 2018 16:40:11 GMT-0700 (PDT)                            
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE                     amptest-20180827155531-apiamptest-2ZLVICBIDXT2 AWS::CloudFormation::Stack Mon Aug 27 2018 16:40:15 GMT-0700 (PDT) 
CREATE_COMPLETE                     apiamptest                                     AWS::CloudFormation::Stack Mon Aug 27 2018 16:40:19 GMT-0700 (PDT) 
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS amptest-20180827155531                         AWS::CloudFormation::Stack Mon Aug 27 2018 16:40:22 GMT-0700 (PDT) 
⠋ Updating resources in the cloud. This may take a few minutes...
GraphQL endpoint: https://6xrakp6p6zd67jleb2oziku3vi.appsync-api.us-east-1.amazonaws.com/graphql
GraphQL API KEY: da2-6wbtognaljcm7irzwjglvaiyne

✔ All resources are updated in the cloud
f45c89966b0d:amptest kaustavg$ amplify codegen add
? Enter the file name pattern of graphql queries, mutation and subscriptions gra
phql/**/*.graphql
? Choose the code generation language target typescript
? Enter the file name for the generated code API.ts
? Do you want to generate code Yes
✔ Downloaded the schema
✔ code generated successfully and saved in file API.ts


@heitorlessa
Copy link
Contributor

@dabit3 I hit that issue yesterday but didn't open up an issue, here's how I reproduced:

  1. Create a new project, add a new API, add amplify codegen add and push
  2. run amplify remove and let it remove all backend folder, etc.
  3. Try creating again and you'll hit the issue when adding a new api

Reason being is that the file .graphqlconfig.yml doesn't get deleted and if you look closely it still points to the previous API that was deleted - Removing this file and retrying it'll work.

cc @kaustavghosh06

@yuth
Copy link
Contributor

yuth commented Aug 28, 2018

I will add a check in the codegen if the API still available and generate code iff its not deleted. Long term solution to this would be to listen to API add and remove event and update the configurations automatically

@dabit3
Copy link
Contributor Author

dabit3 commented Aug 28, 2018

+1 on @heitorlessa comment. This error went away after removing the .graphqlconfig.yml file & generating again.

kaustavghosh06 added a commit that referenced this issue Aug 28, 2018
Fix(aws-amplify/amplify-cli) #50 Check if the API exists during codegen
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants