Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for KeyConditionInput types #1358

Merged

Conversation

mikeparisstuff
Copy link
Contributor

@mikeparisstuff mikeparisstuff commented Apr 27, 2019

Issue #, if available:

Implements work item one from #1062

Solves #1242

Description of changes:

Adds support for key condition input objects on @connection types.

Quoted from the RFC:

There is currently no support for passing sort key conditions to query operations created by the @connection directive. Key conditions offer a different set of operator than filter expressions so we are unable to reuse the ModelXFilterInput types that are currently generated. Read more about key conditions in the Amazon DynamoDB docs https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html.

Given a schema:

type Post @model {
  id: ID!
  name: String!
  comments: [Comment] @connection(name: "PostComments", keyField: "postId", sortField: "statusDate")
}

type Comment @model(queries: null) {
  id: ID!
  post: Post! @connection(name: "PostComments", keyField: "postId", sortField: "statusDate")
  postId: ID!
  statusDate: String!
}

This work would generate additional input types and update the generated connection resolver.

# The new input types.
input ModelStringKeyConditionInput {
  eq: String
  le: String
  lt: String
  ge: String
  gt: String
  beginsWith: String
  between: [String]
}

input ModelIDKeyConditionInput {
  eq: ID
  le: ID
  lt: ID
  ge: ID
  gt: ID
  beginsWith: ID
  between: [ID]
}

input ModelIntKeyConditionInput {
  eq: Int
  le: Int
  lt: Int
  ge: Int
  gt: Int
  between: [Int]
}

input ModelFloatKeyConditionInput {
  eq: Float
  le: Float
  lt: Float
  ge: Float
  gt: Float
  between: [Float]
}
# The updated post type
type Post {
  id: ID!
  name: String!

  # new statusDate sort key condition input
  comments(
    statusDate: ModelStringKeyConditionInput, 
    filter: ModelCommentFilterInput, 
    sortDirection: ModelSortDirection, 
    limit: Int, 
     nextToken: String
  ): ModelCommentConnection
}

With this in place you can create comments with a "statusDate" such as "PUBLISHED_2019-04-25" and then run a query like shown below to get a post and its comments published in April, 2019.

query {
  getPost(id: 1) {
    comments(statusDate: { beginsWith: "PUBLISHED_2019-04" }) {
      items {
        ...
      }
    }
  }
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@yuth yuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@mikeparisstuff mikeparisstuff merged commit 7a17a3f into aws-amplify:master May 6, 2019
@ghost ghost removed the review label May 6, 2019
@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants