The Wayback Machine - https://web.archive.org/web/20220424043300/https://github.com/aws-amplify/amplify-cli/pull/1463
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

Feature/@key #1463

Merged
merged 23 commits into from May 29, 2019
Merged

Feature/@key #1463

merged 23 commits into from May 29, 2019

Conversation

Copy link
Contributor

@mikeparisstuff mikeparisstuff commented May 16, 2019

Issue #, if available:

#1062

Description of changes:

Still a work in progress. This is the initial work for custom indexes. I have a few more things to finish so please do not merge this yet. These features require substantial changes so I want to start the PR process earlier rather than later.

Complete:

  • Implement @key and handle updating DynamoDB table primary and secondary index structures.
  • Advanced @key validation.
  • Update auto-generated get, create, update, and delete operations for custom primary keys.
  • Update GraphQL schema to work with custom primary keys.
  • Auto-generate composite keys when indexing on 3 or more attributes for get, create, update, delete.
  • Tests for schema structural changes
  • Tests for get, create, update, delete operation with composite and simple keys.
  • Update list operation to work with custom primary keys.
  • Tests for list operations
  • Implement query resolver when instructed for secondary indexes.
  • Tests for query operations
  • Rework composite key condition input shape to be more logically consistent.
  • Write docs.
  • Handle unique partial composite key update in update operations using one of two strategies. 1. Pre-fetch key and allow partial updates. 2. Force update mutation to include all parts of composite key if any are included.

Work remaining:

  • ?

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

@ranguard
Copy link

@ranguard ranguard commented May 20, 2019

excited (sorry can't be technically constructive but wanted to show thanks)

@janhesters
Copy link

@janhesters janhesters commented May 25, 2019

Will there be a way to dynamically specify the keys client-side like so

API.graphql(graphqlOperation(listContacts, { limit: 100, nextToken, sortBy: { firstName: 'gte', lastName: 'gte' }));

? Or if that's not possible, will we be able to add multiple query fields like

type Contact 
  @model 
  @key(name: "ByOwnerLastNameFirstName", fields: ["owner", "lastName", "firstName"], queryField: "contactsByOwnerAndName")
  @key(name: "ByOwnerCityLastNameFirstName", fields: ["owner", "city", "lastName", "firstName"], queryField: "contactsByOnwerAndCity")
  @auth(rules: [{ allow: owner }]) 
{
  id: ID!
  firstName: String
  lastName: String
  city: String
  email: String
  telephone: String
  owner: String
}

?

@mikeparisstuff
Copy link
Contributor Author

@mikeparisstuff mikeparisstuff commented May 28, 2019

@janhesters Unfortunately there is no such thing as a dynamic sort by argument in DynamoDB but yes you are able to add multiple query fields exactly like you mentioned.

edit: I should mention that you can dictate the direction that an index is scanned/queried dynamically.

if (deleteResolver) {
deleteResolver.Properties.RequestMappingTemplate = joinSnippets([
this.setKeySnippet(directive, true),
ensureCompositeKeySnippet(directive),
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

Do we need this? Since we don't support batch delete do we need to ensure composite key

Copy link
Contributor Author

@mikeparisstuff mikeparisstuff May 29, 2019

Choose a reason for hiding this comment

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

Nope we do not. Removed.

const finalSortKeyField = definition.fields.find(f => f.name.value === finalSortKeyFieldName);
// All composite keys (length > 2) are casted to strings.
const sortKeyConditionInput = args.fields.length > 2 ?
makeScalarKeyConditionForType(makeNamedType('String')) :
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

As discussed can we make this simpler as we know the fields.length is 2

Copy link
Contributor Author

@mikeparisstuff mikeparisstuff May 29, 2019

Choose a reason for hiding this comment

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

Updated

Copy link
Contributor

@kaustavghosh06 kaustavghosh06 left a comment

LGTM.

@kaustavghosh06 kaustavghosh06 merged commit 00ed819 into aws-amplify:master May 29, 2019
2 checks passed
GRAPHQL_CLIENT = new GraphQLClient(endpoint, { 'x-api-key': apiKey })
});

// afterAll(async () => {
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

Can we have the cleanup back

@@ -0,0 +1,163 @@
# Testing Custom Indexes
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

We don't need this anymore right

import ModelTransformer from 'graphql-dynamodb-transformer';
import KeyTransformer from 'graphql-key-transformer';
import { parse, FieldDefinitionNode, ObjectTypeDefinitionNode } from 'graphql';
import { expectArguments, expectFields, expectNonNullFields, expectNullableFields } from '../testUtil';
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

Are we using expectFields?

} from 'graphql';
import { isNonNullType } from 'graphql-transformer-common';

export function expectFields(type: ObjectTypeDefinitionNode, fields: string[]) {
Copy link
Contributor

@yuth yuth May 29, 2019

Choose a reason for hiding this comment

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

Extending the matcher would be a better approach. More on this at jest docs

@janhesters
Copy link

@janhesters janhesters commented Jun 8, 2019

@mikeparisstuff

I should mention that you can dictate the direction that an index is scanned/queried dynamically.

How? 😊

@github-actions
Copy link

@github-actions github-actions bot commented May 25, 2021

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
5 participants