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

Failed to start API Mock endpoint #1997

Closed kldeb closed 4 years ago

kldeb commented 5 years ago

Describe the bug When I run amplify mock it sets up the storage and creates the tables properly. It tells me that elastic search is not supported but then i get the following error:

Failed to start API Mock endpoint Error: Invalid config for UNIT_RESOLVER {"dataSourceName":"ElasticSearchDataSource","typeName":"Query","fieldName":"searchAccounts","requestMappingTemplateLocation":"resolvers/Query.searchAccounts.req.vtl","responseMappingTemplateLocation":"resolvers/Query.searchAccounts.res.vtl","kind":"UNIT"}
 Missing data source ElasticSearchDataSource

Can mock bypass this error so that I can at least use the other features?

To Reproduce Steps to reproduce the behavior:

  1. have existing amplify project with @searchable on at least one object
  2. upgrade to latest amplify cli
  3. run amplify mock
  4. See error

Expected behavior Not get an error and be able to use mock.

Desktop (please complete the following information):

Additional context My graphql transform compiles without errors via CLI and amplify console.

rpostulart commented 5 years ago

I still have this issue, see my comment here:

https://github.com/aws-amplify/amplify-cli/pull/1999#issuecomment-525882093

yuth commented 5 years ago

@rpostulart could you share a minimal project where we can reproduce this issue

rpostulart commented 5 years ago

Of course what do you need? At least here is my scheme:

type Event @model @searchable{
  id: ID!
  date: String!
  polygon: Location
  subscribers: [EventSubscribers] @connection(name: "EventEvent")
  eventOwner: Subscriber! @connection
  name: String!
  description: String
  coordinates: [Coordinate]
  planned: Boolean
}

type EventSubscribers @model(queries: null){
  id: ID!
  event: Event! @connection(name: "EventEvent")
  subscriber: Subscriber! @connection(name: "EventSubscriber")
  createdAt: String
}

type Subscriber @model @searchable{
  id: ID!
  name: String
  email: String
  phone: String
  device: String
  addressLocation: Location
  address: String
  complete: Boolean
  events: [EventSubscribers] @connection(name: "EventSubscriber")
  planning: [Planning] @connection(name: "SubscriberPlanning")
}

type Planning @model{
 id: ID!
 event: Event
 subscriber: Subscriber @connection(name: "SubscriberPlanning")
 location: Location
 type: String
 time: String
 notificationSend: Boolean
}

type Location {
  type: String
  coordinates: [[[Float]]]
}
type Coordinate{
  longitude: Float
  latitude: Float
}

input LocationInput {
  type: String
  coordinates: [[[Float]]]
}

type EventConnection {
  items: [Event]
  total: Int
  nextToken: String
}

input PointInput {
  type: String
  coordinates: [Float]
}

type Query {
  nearbyEvent(location: PointInput!): EventConnection
}

type Mutation {
  sendNotification(input: NotificationInput): NotificationResult @function(name: "sendNotifications-${env}")
}

type NotificationResult {
    result: String
}
input NotificationInput {
    action: String
    data: String
}
federicopuntoni commented 5 years ago

same here with simple lambda as source:

Node: v10.16.3

/api /resolvers Query.echo.req.vtl Query.echo.res.vtl /stacks CustomResources.json schema.graphql

schema.graphql:

type Query {
  echo(msg: String): String
}

CustomResources.json:

.
.
.
"QueryEchoResolver": {
      "Type": "AWS::AppSync::Resolver",
      "Properties": {
        "ApiId": {
          "Ref": "AppSyncApiId"
        },
        "DataSourceName": {
          "Fn::GetAtt": [
            "proxyGraphQLLambdaDataSource",
            "Name"
          ]
        },
        "TypeName": "Query",
        "FieldName": "echo",
        "RequestMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.echo.req.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        },
        "ResponseMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.echo.res.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        }
      }
    }
,
,
,

Query.echo.req.vtl:

{
    "version": "2017-02-28",
    "operation": "Invoke",
    "payload": {
        "type": "Query",
        "field": "echo",
        "arguments": $utils.toJson($context.arguments),
        "identity": $utils.toJson($context.identity),
        "source": $utils.toJson($context.source)
    }
}
amplify mock
Failed to start API Mock endpoint Error: Invalid config for UNIT_RESOLVER {"dataSourceName":"proxyGraphQLLambda","typeName":"Query","fieldName":"echo","requestMappingTemplateLocation":"resolvers/Query.echo.req.vtl","responseMappingTemplateLocation":"resolvers/Query
.echo.res.vtl","kind":"UNIT"}
 Missing mapping template resolvers/Query.echo.req.vtl
federicopuntoni commented 5 years ago

If it can be useful I add that I run "amplify mock" from Windows 10.

From the error we see that the template is searched in the path as:

"Resolvers / Query.echo.req.vtl"

to notice instead that the path of Windows is with backslash:

"Resolvers \ Query.echo.req.vtl"

federicopuntoni commented 5 years ago

also, the resolvers folder in build/ is empty

ben-elsen commented 4 years ago

Is there any update on this?

yuth commented 4 years ago
 "QueryEchoResolver": {
      "Type": "AWS::AppSync::Resolver",
      "Properties": {
        "ApiId": {
          "Ref": "AppSyncApiId"
        },
        "DataSourceName": {
          "Fn::GetAtt": [
            "proxyGraphQLLambdaDataSource",
            "Name"
          ]
        },
        "TypeName": "Query",
        "FieldName": "echo",
        "RequestMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.echo.req.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        },
        "ResponseMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.echo.res.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        }
      }
    }

@federicopuntoni Where is proxyGraphQLLambdaDataSource defined. Could you share the cloudformation template where this data source is defined

bugzbuks commented 4 years ago

Also getting the same issue. I'm busy with the Amplify tutorial Part 1. I'm using the same settings as the example shows. However, the mock API fuction failed as shown below $ amplify mock api Failed to start API Mock endpoint Error: not found: java

yuth commented 4 years ago

@bugzbuks Amplify Mock needs Java to be installed in your computer to start DynamoDB local. Could you please install the latest version of Java and see if the issue gets resolved

bugzbuks commented 4 years ago

@Yuth Java is installed and working.

flowtrader2016 commented 4 years ago

Same issue: "Failed to start API Mock endpoint Error: No AppSync API is added to the project"

I do have an API though as per:

$ amplify add codegen --apiId xxxxxxxxxxx Gives response: "Codegen support only one GraphQL API per project"

Also Java is installed and working.

yuth commented 4 years ago

I do have an API though as per:

$ amplify add codegen --apiId xxxxxxxxxxx

If you add an API to your project with --apiId you can use that API only for codegen. Mock needs API to be provisioned in the project and does not work with externally provisioned API

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.