Why do Appsync Mutations return null

0

Hello,

I have a basic schema in AppSync for an API

type Location {
	id: Int!
}

type Mutation {
	pushLocation(id: Int!): Location
}

type Query {
	getLocation(id: Int!): Location
}

type Subscription {
	subscribeToLocation(id: Int!): Location
		@aws_subscribe(mutations: ["pushLocation"])
}

schema {
	query: Query
	mutation: Mutation
	subscription: Subscription
}

and with a simple mutation

mutation MyMutation {
  pushLocation(id: 10) {
    id
  }
}

but every time I run the mutation in the query console area I get a null response as below

{
  "data": {
    "pushLocation": null
  }
}

however, using the default AppSync API example & schema, the mutation always returns a response

What am I missing? I've compared the 2 API's carefully and their configurations are the same.

Thanks in advance

Regards,

Jason

質問済み 6ヶ月前299ビュー
1回答
1
承認された回答

Hi. This is most likely because you do not have a resolver set for your mutation. Try following steps -

  1. In AppSync console, in left navigation, click on "Schema"
  2. On next page, in right section under "Resolvers", search for Mutation list
  3. Next to publish(...): Channel, click on "Attach" button
  4. On next page, change resolver type to VTL.
  5. From DataSource dropdown, select NoneDataSource.
  6. Click Create
  7. Under Configure Mapping Template, change to following code -
{
    "version": "2017-02-28",
    "payload": {
        "id": "$context.arguments.id"
    }
}
  1. Click Save
  2. Go back to Queries page and retest.

To make this work with your business logic you will have to implement resolvers. Read more here - https://docs.aws.amazon.com/appsync/latest/devguide/resolver-components.html

AWS
回答済み 6ヶ月前
  • Thank you, this solved the problem for me.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ