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

Add updatedAt to ignored input fields in sdl creation #777

Merged
merged 2 commits into from
Jul 16, 2020

Conversation

leibowitz
Copy link
Contributor

@leibowitz leibowitz commented Jun 30, 2020

Currently only id and createdAt fields are skipped when creating and updating a record, when creating the sdl for a model. Therefore any non-null updatedAt field will cause the create to fail in the scaffold, because it is still defined in the graphql input type as required.

Note updatedAt is already ignored in the scaffold:

const NON_EDITABLE_COLUMNS = ['id', 'createdAt', 'updatedAt']

Currently only id and createdAt are skipped when creating and updating a record. Therefore any non-null updatedAt field will fail because it is still defined in the graphql input type, but updatedAt is ignored in the scaffold

https://github.com/redwoodjs/redwood/blob/5e514213a50b2d8d53d508e05f81452936a7450f/packages/cli/src/commands/generate/scaffold/scaffold.js#L34
@leibowitz leibowitz changed the title Add updatedAt to ignored input fields Add updatedAt to ignored input fields in sdl creation Jun 30, 2020
@leibowitz
Copy link
Contributor Author

Just to be clear, here is what my schema looks like, and what scaffold sdl generated:
api/prisma/schema.prisma:

datasource DS {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider      = "prisma-client-js"
  binaryTargets = env("BINARY_TARGET")
}

model User {
  id                                Int                  @default(autoincrement()) @id
  createdAt                         DateTime             @default(now())
  updatedAt                         DateTime             @default(now()) @updatedAt
  full_name                         String
  email                             String
}

api/src/graphql/users.sdl.js:

import gql from 'graphql-tag'

export const schema = gql`
  type User {
    id: Int!
    createdAt: DateTime!
    updatedAt: DateTime!
    full_name: String!
    email: String!
  }

  type Query {
    users: [User!]!
    user(id: Int!): User!
  }

  input CreateUserInput {
    updatedAt: DateTime!
    full_name: String!
    email: String!
  }

  input UpdateUserInput {
    updatedAt: DateTime
    full_name: String
    email: String
  }

  type Mutation {
    createUser(input: CreateUserInput!): User!
    updateUser(id: Int!, input: UpdateUserInput!): User!
    deleteUser(id: Int!): User!
  }
`

And I get this error on create, in the scaffold:

An error has occurred
Field updatedAt of required type DateTime! was not provided.

@cannikin cannikin merged commit d43adf6 into redwoodjs:main Jul 16, 2020
@cannikin
Copy link
Member

Thanks!

@thedavidprice thedavidprice added this to the next release milestone Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants