Amplify-cli: Is model connection transforms actually working?

Created on 8 Feb 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

So I have a model with a connection. However, when loading in the object that has connections only 10 items appear, with no way to change the limit or use the nextToken to get more items.

My model looks like this.

type User @model @searchable {
    id: ID!
    votes: [Vote] @connection(name: "UserVote")
}

type Vote @model @searchable {
    id: ID!
    user: User! @connection(name: "UserVote")
    vote: Int!
}

If I do GetUserQuery(id: userId) from iOS Swift, I correctly get back the user object with some nested votes. But only 10 votes appear in result?.data?.getUser?.votes?.items although there are more. I do have the result?.data?.getUser?.votes?.nextToken. But Since I'm only calling getUser and expect all the votes belonging to a user to come back, how can I get all the votes out?

code-gen graphql-transformer question

All 4 comments

Does the ListVotes query work? That should also get you a nextToken for pagination.

@wizawuza yeah but that will give me all the votes. I want the votes only for that user which is the whole point with the connection.

I presume ListVotes is doing a scan which will be inefficient to then filter on. As scan loads everything then filter afterwards.

@helloniklas you will have to update your query to something like this to so that you can pass the limit to the votes you want to see in the result. The codegen generated query handles very base case, as its intended to be a starting point for writing query and not to handle all the use cases.

query getUser($userId: ID, $voteLimit: Int) {
  listUsers(filter: { id: { eq: $userId } }) {
    items {
      id
      votes(limit: $voteLimit) {
        items {
          id
          vote
        }
      }
    }
  }
}

Hope this helps. Feel free to re-open this issue if it doesn't

@yuth Ok, seems like a bug that the default generated query only gives me the first 10 votes on the connection but not more... The generated query doesn't seem to use list either... but I'll look into it a bit more. Not sure what the @connection actually is doing then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ffxsam picture ffxsam  路  3Comments

zjullion picture zjullion  路  3Comments

nicksmithr picture nicksmithr  路  3Comments

nason picture nason  路  3Comments

adriatikgashi picture adriatikgashi  路  3Comments