AppSync List Query Returns Empty Array from JS Client App, but Populated Array from AppSync Console

Viewed 638

When running a list query from the AppSync console, I get back an array with 3 items (this is expected, as I have three corresponding items in my DynamoDB table).

When I run the exact same query from my React client application, I get an empty array. I've tried messing around with the @auth decorator in my schema.graphql file, but so far to no avail. I also experience the same behavior when running the query from Postman - I get an empty items array.

Type definition in schema.graphql:

type Item @model @auth(rules: [
    { allow: owner },
    { allow: public, provider: iam, operations: [read] }]) {
    id: ID!
    itemName: String!
    anotherProperty: String!
    anotherProperty: String!
    anotherProperty: String!
    anotherProperty: String
    anotherProperty: AnotherType @connection
    anotherProperty: String
    anotherProperty: String
    anotherProperty: String
    anotherProperty: String
    anotherProperty: String
    anotherProperty: SomeType @connection
    anotherProperty: [SomeOtherType] @connection(keyName: "byItemID", fields: ["id"])
    anotherProperty: String
    anotherProperty: [YetAnotherType] @connection(keyName: "byItemID", fields: ["id"])
}

Client code where I call the API (ClojureScript):

(re-frame/reg-event-fx
              ::list-items
              (fn list-items-handler []
                (-> (.graphql API (graphqlOperation "query { listItems { items { itemName } } }"))
                                 (.then (fn list-items-res [url]
                                          (js/console.log url))))))

Response to call from client application:

{"data":{"listItems":{"items":[]}}}

Same query from the AppSync Console:

query ListItems {
  listItems {
    items {
      itemName
    }
  }
}

Response to call from AppSync Console:

{
  "data": {
    "listItems": {
      "items": [
        {
          "itemName": "Thingy"
        },
        {
          "itemName": "Contraption"
        },
        {
          "itemName": "Apparatus"
        }
      ]
    }
  }
}

I'm not sure what I'm doing wrong. I suspect it has something to do with the permissions set with @auth, but I can't figure out what that might be. Any help would be appreciated. Thanks in advance!

0 Answers
Related