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

amplify push error - resolvers directory not found #298

Closed joebernard closed 5 years ago

joebernard commented 5 years ago

Describe the bug After adding a graphql API and pushing I receive this error: ENOENT: no such file or directory, scandir '/opt/projects/myApp/amplify/backend/api/myApp/build/resolvers'

To Reproduce Steps to reproduce the behavior: amplify init amplify add api use default options amplify push error

Expected behavior The API service should deploy

Desktop (please complete the following information):

Additional context I have tried amplify delete and then the steps above and still get the issue. I've also tried manually adding the resolvers directory where it is specified, but it deletes as part of the build process and then throws the error.

kaustavghosh06 commented 5 years ago

@joebernard Can you share your annotated schema? I’ve seen this error when there’s not a single annotation in the schema.

joebernard commented 5 years ago

I chose to let the tool create a new schema with a single type (myType).

type MyType @model {
    id: ID!
    title: String!
    content: String!
    price: Int
    rating: Float
}

Also, I just updated to @aws-amplify/cli@0.1.28-beta.0 and the issue seems to be fixed in that version.

SudduK commented 5 years ago

Hi Joe,

I got the same error that "ENOENT: no such file or directory, scandir 'amplify\backend\api\CLAGraphQL\build\resolvers'"

Thanks for directing to use @aws-amplify/cli@0.1.28-beta.0 instead, but I am facing the below issue however:

npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue npm WARN inquirer-autocomplete-prompt@1.0.1 requires a peer of inquirer@^5.0.0 | | ^6.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! path C:\Users\userid\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\npm\node_modules\ansistyles npm ERR! code ENOENT npm ERR! errno -4058 npm ERR! syscall rename npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\userid\AppData\Roaming\npm\node_modules\@aws-amplify\cli\node_modules\npm\node_modules\ans istyles' -> 'C:\Users\userid\AppData\Roaming\npm\node_modules\@aws-amplify\cli \node_modules\npm\node_modules.ansistyles.DELETE' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\userid\AppData\Roaming\npm-cache_logs\2018-10-15T03_13_54_462Z-debug.log

Any thoughts on the above error?

joebernard commented 5 years ago

Update on this: I tried setting up a new API with amplify and got the resolvers issue. I'm using @aws-amplify/cli@0.1.28-beta.0.

I ran amplify remove api then amplify add api, went through the setup steps and it worked.

The only difference was in the failed attempt I specified an existing graphQL schema, and in the successful attempt I did not.

joebernard commented 5 years ago

@SudduK That looks like a different issue. Open a new ticket.

SudduK commented 5 years ago

@joebernard : Will create a new ticket for issue with Amplify CLI installation version 0.1.28-beta.0

However, the underlying issue with "scandir resolvers not found" still exists for me with @aws-amplify/cli@0.1.27 ENOENT: no such file or directory, scandir 'amplify\backend\api\CLAGraphQL\build\resolvers'

I followed below steps to push the new Graphql API service to AWS AppSync using the Graphql schema (.graphql) which indeed was generated from a AppSync Project in AWS Console.

1) Exported the AWS AppySync schema from AWS console in .Graphql format 2) Install the AWS Amplify CLI npm install -g @aws-amplify/cli 3) Create a amplify project amplify init 3) Create a new Graphql API amplify api add 4) Push the GraphQL Api to the AWS AppSync amplify api push Facing the error at step 4. ENOENT: no such file or directory, scandir 'amplify\backend\api\CLAGraphQL\build\resolvers'

Note: Have also tried to copy the resolver .vtl files into both directory amplify\backend and also amplify\backend\api\CLAGraphQL\build\resolvers and that failed to work

Please let me know if you have figured out this issue or see any thing that is missing in the above steps Thank you!

SunJang commented 5 years ago

Same issue.

I have tried three versions(0.1.27, 0.1.28-beta.0, 0.2.0-alpha.0a106b94) and still got an error.

I chose "Do you have and annotated GraphQL schema" as "Y" and selected existing schema file exported from AWS Appsync console.

realjangsun at realjangsunui-MacBook-Pro in ~/workspace/signal9/icon-css/amplify on master [!]
$ amplify api add
? Please select from one of the below mentioned services GraphQL
? Provide API name: iconcss
? Choose an authorization type for the API API key
? Do you have an annotated GraphQL schema? Yes
? Provide your schema file path: /Users/realjangsun/Downloads/schema.graphql

GraphQL schema compiled successfully. Edit your schema at /Users/realjangsun/workspace/signal9/icon-css/amplify/backend/api/iconcss/schema.graphql
Successfully added resource iconcss 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

It compiled successfully. But when I try to push it an error occurs

realjangsun at realjangsunui-MacBook-Pro in ~/workspace/signal9/icon-css/amplify on master [!]
$ amplify push
| Category | Resource name | Operation | Provider plugin   |
| -------- | ------------- | --------- | ----------------- |
| Api      | iconcss       | Create    | awscloudformation |
? Are you sure you want to continue? true

GraphQL schema compiled successfully. Edit your schema at /Users/realjangsun/workspace/signal9/icon-css/amplify/backend/api/iconcss/schema.graphql
✖ An error occurred when pushing the resources to the cloud

ENOENT: no such file or directory, scandir '/Users/realjangsun/workspace/signal9/icon-css/amplify/backend/api/iconcss/build/resolvers'

OS: Mac 10.13.6 Node: 9.4.0

joebernard commented 5 years ago

Try removing the API, then adding it again. I found that it would fail the first time, but if I dropped it and re-added it, it worked.

amplify remove api amplify add api

kaustavghosh06 commented 5 years ago

@SunJang AND @SudduK Could you please share your annotated schemas?

SunJang commented 5 years ago

@kaustavghosh06 Unfortunately, I delete all (I am still under testing)

As far as I remember, if I create api by "amplify api add" then it fails when trying to push. But if I create api by "amplify codegen add --appId xxxxxxxxxxxxx", it worked.

SudduK commented 5 years ago

@kaustavghosh06 Please find the graphql schema I am trying to add. `schema { query: Query mutation: Mutation subscription: Subscription }

type Conversation {

The Conversation's timestamp.

createdAt: String

A unique identifier for the Conversation.

id: ID!

The Conversation's messages.

messages(after: String, first: Int): MessageConnection

The Conversation's name.

name: String! }

type Message {

The author object. Note: authorId is only available because we list it in extraAttributes in Conversation.messages

author: User

The message content.

content: String!

The id of the Conversation this message belongs to. This is the table primary key.

conversationId: ID!

The message timestamp. This is also the table sort key.

createdAt: String

Generated id for a message -- read-only

id: ID!

Flag denoting if this message has been accepted by the server or not.

isSent: Boolean recipient: User sender: String }

type MessageConnection { messages: [Message] nextToken: String }

type Mutation {

Create a Conversation. Use some of the cooked in template functions for UUID and DateTime.

createConversation(createdAt: String, id: ID!, name: String!): Conversation

Create a message in a Conversation.

createMessage(content: String, conversationId: ID!, createdAt: String!, id: ID!): Message

Put a single value of type 'User'. If an item does not exist with the same key the item will be created. If there exists an item at that key already, it will be updated.

createUser(username: String!): User

Put a single value of type 'UserConversations'. If an item does not exist with the same key the item will be created. If there exists an item at that key already, it will be updated.

createUserConversations(conversationId: ID!, userId: ID!): UserConversations }

type Query {

Scan through all values of type 'Message'. Use the 'after' and 'before' arguments with the 'nextToken' returned by the 'MessageConnection' result to fetch pages.

allMessage(after: String, conversationId: ID!, first: Int): [Message]

Scan through all values of type 'MessageConnection'. Use the 'after' and 'before' arguments with the 'nextToken' returned by the 'MessageConnectionConnection' result to fetch pages.

allMessageConnection(after: String, conversationId: ID!, first: Int): MessageConnection allMessageFrom(after: String, conversationId: ID!, first: Int, sender: String!): [Message]

Scan through all values of type 'User'. Use the 'after' and 'before' arguments with the 'nextToken' returned by the 'UserConnection' result to fetch pages.

allUser(after: String, first: Int): [User]

Get my user.

me: User }

type Subscription {

Subscribes to all new messages in a given Conversation.

subscribeToNewMessage(conversationId: ID!): Message @aws_subscribe(mutations : ["createMessage"]) subscribeToNewUCs(userId: ID!): UserConversations @aws_subscribe(mutations : ["createUserConversations"]) subscribeToNewUsers: User @aws_subscribe(mutations : ["createUser"]) }

type User {

A unique identifier for the user.

cognitoId: ID!

A user's enrolled Conversations. This is an interesting case. This is an interesting pagination case.

conversations(after: String, first: Int): UserConverstationsConnection

Generated id for a user. read-only

id: ID!

Get a users messages by querying a GSI on the Messages table.

messages(after: String, first: Int): MessageConnection

is the user registered?

registered: Boolean

The username

username: String! }

type UserConversations { associated: [UserConversations] conversation: Conversation conversationId: ID! user: User userId: ID! }

type UserConverstationsConnection { nextToken: String userConversations: [UserConversations] }

type schema { mutation: Mutation query: Query subscription: Subscription } ` Basically, this is the schema of the AWS AppSync API that is already provisioned using the Chat App (sample Project) in AWS Console and all the dynamodb resources are also provisioned. (Not sure if I going right path!!) I am trying to generate the client-side typescript code for this project to be used in angular6 application

When trying to push the schema to cloud using "amplify api push", getting the below error:

| Category | Resource name | Operation | Provider plugin | | Api | ChatTestSample | Create | awscloudformation | ? Are you sure you want to continue? true GraphQL schema compiled successfully. Edit your schema at "..\AWSAmplify\amplify\backend\api\ChatTestSample/schema.graphql" x An error occurred when pushing the resources to the cloud

ENOENT: no such file or directory, scandir '..\AWSAmplify\amplify\backend\api\ChatTestSample\build\resolvers'

kaustavghosh06 commented 5 years ago

@SudduK You would need to add at least one annotation to your annotate schema for it to be successfully compiled and pushed. For more information on GraphQL annotated schemas, please check out -> https://github.com/aws-amplify/amplify-cli/blob/master/graphql-transform-tutorial.md

SudduK commented 5 years ago

@kaustavghosh06 Thanks Kaustav. I will go through this reference and let you know what I find out. (ignored this earlier)

SudduK commented 5 years ago

The below worked for me as well, except that I have setup apiKey in addition to what @SunJang commented above. amplify add codegen --apiId XXXXXXX --apiKey XXXXXXX Thanks everyone

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.