amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

APIPlugin support sort parameter on models with `@key`

Open lawmicha opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. When using @key directive on a model to create a provisioned API with the sort parameter.

type Todo @model 
@key(name:"byA",fields:["field1","field2"],queryField:"byField1") {
  id: ID!
  field1: String!
  field2: Float!
}

Describe the solution you'd like Allow a way to pass in parameters at the GraphQLRequest builders

Amplify.API.query(.paginatedList(Todo.self, limit: 100, sort: SortInput.ascending)

Describe alternatives you've considered Following https://docs.amplify.aws/lib/graphqlapi/advanced-workflows/q/platform/ios to creating my own custom GraphQLRequest

extension GraphQLRequest {
    static func listTodos(nextToken: String? = nil) -> GraphQLRequest<ListTodo> {
        let operationName = "listTodos"
        let document = """
        query listTodos($limit: Int, $sort: SortInput, $nextToken: String) {
          \(operationName)(limit: $limit, sort: $sort, nextToken: $nextToken) {
            items {
              id
              field1
              field2
            }
          }
        }
        """
        var variables = ["limit": 100, "sort": "asc"]
        if let nextToken = nextToken {
          variables.update(nextToken, forKey: "nextToken")
        }
        return GraphQLRequest<ListTodo>(document: document,
                                    variables: variables,
                                    responseType: ListTodo.self,
                                    decodePath: operationName)
    }
}

struct ListTodo {
   var items: [Todo]
   var nextToken: String?
}

or use DataStore's supoprt for querying with a sort and page size: https://docs.amplify.aws/lib/datastore/data-access/q/platform/ios#sort

Additional context Add any other context or screenshots about the feature request here.

lawmicha avatar Jan 22 '21 21:01 lawmicha

This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.

github-actions[bot] avatar Jun 19 '21 00:06 github-actions[bot]

I would like this as well

DanielZanchi avatar Mar 02 '23 16:03 DanielZanchi

Since V2 transformer was released, the original feature request should be refactored to use @primaryKey and @index instead of @key (latest CLI docs https://docs.amplify.aws/cli/graphql/data-modeling/#configure-a-secondary-index). This issue should still be open since we do not provide the sort parameter on the GraphQLRequest builders

lawmicha avatar Aug 10 '23 15:08 lawmicha