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

Jason
asked 5 months ago240 views
1 Answer
1
Accepted Answer

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
answered 5 months ago
  • Thank you, this solved the problem for me.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions