Amplify-cli: 'Type Query not found' when pushing new environment

Created on 17 Nov 2020  路  7Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
When I try to push new environment I get error:
Type Query not found (Service: AWSAppSync; Status Code: 404; Error Code: NotFoundException)

Amplify CLI Version
4.32.1

To Reproduce
amplify env add prod
amplify push

Expected behavior
The new environment to be created

Screenshots
Resource Name: QuerynearbyTowersResolver (AWS::AppSync::Resolver) Event Type: create Reason: Type Query not found (Service: AWSAppSync; Status Code: 404; Error Code: NotFoundException; Request ID: 165cf41b-0319-42e5-a72e-47cde4b9bae9; Proxy: null)

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: 14.11.0
api-graphql pending-response pending-triage

Most helpful comment

I managed to get a custom Query backed by a Lambda resolver working by removing the @auth Amplify-supplied annotation I use elsewhere and using AppSync's @aws_iam and @aws_cognito_user_pools annotations instead.

I hadn't used those annotations before as stuck with Amplify's @auth annotation, but I ran into various issues whatever I tried when using that annotation.

All 7 comments

There is a GraphQL API in your project based the error message, we'll need to get more information on the API to investigate further. Could you share the schema of the GraphQL API? you can edited out sensitive information if there is any, just any schema that would reproduce this issue.
You can share it here, or send it through email to this address: [email protected] with subject: Re: Github issue #5892

@UnleashedMind thank you for your reply!
Here is the schema:

type Player @model(subscriptions: null) @key(fields: ["owner"]) 
  @key(name: "byScore", fields: ["type", "score"], queryField: "getPlayersByScore")
  @auth(rules: [
    { allow: private, operations: [read] },
    { allow: private, provider: iam }
  ]) {
  type: String! 
  owner: String!
  score: Int!
  towers: [Tower] @connection(keyName: "byPlayer", fields: ["owner"])
}

type Tower @model(subscriptions: null) @searchable
  @key(name: "byPlayer", fields: ["playerOwner"]) 
  @auth(rules: [
        { allow: private, provider: iam },
        { allow: private, operations: [read] }
      ]) {
  id: ID!
  location: Location!
  playerOwner: String!
  player: Player @connection(fields: ["playerOwner"])
}

type Location {   
  lat: Float!   
  lon: Float! 
}

type Query {
 nearbyTowers(
   location: LocationInput!, 
   m: Int, 
   limit: Int, 
   nextToken: String
 ): ModelTowerConnection @auth(rules: [
      { allow: private, provider: userPools }
      { allow: private, provider: iam }
    ])
}

input LocationInput {
  lat: Float!
  lon: Float!
}

type ModelTowerConnection {
 items: [Tower]
 total: Int
 nextToken: String
}

My best guess is that is somehow related to Elastic Search which I use in the project.

The issue is not about pushing to new environment or the @seachable, but with the type Query you inserted into your schema, I was able to push and change env with type Query removed.
Making a reference to another issue on how custom query should be setup.
https://github.com/aws-amplify/amplify-cli/issues/5878

When I tried to remove Query from the scheme and ran amplify push I got the error: No field named nearbyTowers found on type Query. Obviously this is because this field is being used by CustomeResources.json:

"Resources": {
       ...
        "QueryNearbyTowers": {
            "Type": "AWS::AppSync::Resolver",
            "Properties": {
                "ApiId": {
                    "Ref": "AppSyncApiId"
                },
                "DataSourceName": "ElasticSearchDomain",
                "TypeName": "Query",
                "FieldName": "nearbyTowers",
                "RequestMappingTemplateS3Location": {
                    "Fn::Sub": [
                        "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.nearbyTowers.req.vtl",
                        {
                            "S3DeploymentBucket": {
                                "Ref": "S3DeploymentBucket"
                            },
                            "S3DeploymentRootKey": {
                                "Ref": "S3DeploymentRootKey"
                            }
                        }
                    ]
                },
                "ResponseMappingTemplateS3Location": {
                    "Fn::Sub": [
                        "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.nearbyTowers.res.vtl",
                        {
                            "S3DeploymentBucket": {
                                "Ref": "S3DeploymentBucket"
                            },
                            "S3DeploymentRootKey": {
                                "Ref": "S3DeploymentRootKey"
                            }
                        }
                    ]
                }
            }
        }
        ...

I followed this tutorial to implement location based search.
Any advice on how this can be fixed?
Thank you!

@lysachok seems your latest error is related to #5289 which I just ran into today.

@UnleashedMind any chance related issue #5289 can get triaged as it's pretty debilitating for me currently and has been open for a few months without triage.

I managed to get a custom Query backed by a Lambda resolver working by removing the @auth Amplify-supplied annotation I use elsewhere and using AppSync's @aws_iam and @aws_cognito_user_pools annotations instead.

I hadn't used those annotations before as stuck with Amplify's @auth annotation, but I ran into various issues whatever I tried when using that annotation.

@danrivett it helped! Thank you.

Was this page helpful?
0 / 5 - 0 ratings