简体   繁体   中英

AWS Amplify GraphQL query returns null instead of items array

I'm trying to query items from a DynamoDB table using AWS Amplify API, running on React.js.
I have a table named Codes, from which I'm trying to query the items using the following code:

var codesData = await API.graphql(graphqlOperation(queries.listCodes, {
  filter: {
    id: {
      eq: id
    },
    num: {
      eq: 1
    }
  }
}));
console.log(codesData);

As you can see, I want to receive all items that have id value as their "id" attribute, and 1 as their "num" attribute.
When I'm printing the codesData to the console, I get the following response:

Object
    data:
        listCodes: null

So I don't even have the items attribute.

I've tried to search the web for something about that, but couldn't find anything.

In the amplify docs they say that you must create new items after you have added the @searchable directive to your model:

See GraphQL Transform

and there

Note: Support for adding the @searchable directive does not yet provide automatic indexing for any existing data to Elasticsearch.

Create your items anew after you have added @searchable and those items will be displayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM