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

createdAt, updatedAt and id should not be required on inputs / mutations #346

Closed
malcomm opened this issue Feb 5, 2020 · 4 comments
Closed
Labels

Comments

@malcomm
Copy link

malcomm commented Feb 5, 2020

Note: This is a blocker.

Describe the bug

Given the following sample schema:

type Foo
  @model
  @key(fields: ["id", "updatedAt"])
{
  id: ID!,
  updatedAt: AWSDateTime!

In order to create/update a Foo, I am required to supply an updatedAt:

    const input: UpdateFooInput = {
      id: this.foo.id,
      updatedAt: moment().toISOString()
    };
    const input: CreateFooInput = {
      updatedAt: moment().toISOString()
    };

createAt and updatedAt should not be required. I'm OK with them being optional, but I can see an argument for them to be treated as special and not messed with at all.

Amplify CLI Version

4.13.1

To Reproduce

Create a model with above primary index with a sort key.

Expected behavior

createAt and updatedAt should not be required.

Additional context
aws-amplify/amplify-cli#401
aws-amplify/amplify-cli#3347

@SwaySway
Copy link
Contributor

SwaySway commented Feb 6, 2020

Hello @malcomm
These fields are normally not mandatory however when you add @key the fields listed in that directive then become mandatory. Since we do auto-populate the fields for id, createdAt, and updatedAt we can potentially add these in a whitelist when adding @key so they are not set to non-nullable.

@malcomm malcomm changed the title createdAt and updatedAt should not be required on inputs / mutations createdAt, updatedAt and id should not be required on inputs / mutations Feb 6, 2020
@malcomm
Copy link
Author

malcomm commented Feb 6, 2020

Should also consider this field: __typeName. My thinking is that it also should be in the whitelist?

@hirochachacha
Copy link
Contributor

This is aws-amplify/amplify-cli#1657. That's the reason I made https://github.com/hirochachacha/graphql-auto-transformer. @malcomm Perhaps, it might help you as a temporary solution.

@edwardfoyle edwardfoyle removed their assignment Apr 6, 2020
@siegerts siegerts added the feature-request New feature or request label Sep 3, 2021
@alharris-at alharris-at transferred this issue from aws-amplify/amplify-cli May 17, 2022
@renebrandel
Copy link
Contributor

This issue is addressed now. Given this schema:

type Note @model @auth(rules: [
  { allow: public, operations: [read] },
  { allow: owner }]) {
  id: ID! @primaryKey(sortKeyFields: ["createdAt"])
  title: String
  content: String @index
  createdAt: AWSDateTime!
}

The mutation request went through:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants