Updates GraphQL SDL Required Types logic #432
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following discussions in #316 and #324 I made some updates to the SDL generators. Assuming the following
schema.prisma
definition:Currently Redwood generates a CRUD SDL that looks like:
Note that no input types are required in
PostInput
even though they are required in the schema. If you try to save this record, Prisma will throw up a pretty gross error that isn't immediately clear what happened. After pondering the discussion in #316 I discussed with @mojombo and we like the idea proposed by @weaversam8 in which there are two input types, one forCreate
where everything that's required inschema.prisma
is also required in GraphQL, as well as anUpdate
where no fields are required:This is a developer experience decision. If you have a database table with 50 columns, all of which are required for a record to exist, you obviously must provide all of them to create a record. However if you only want to edit a single one, you don't want to have to also send along the 49 other required fields along with the 1 you actually need to change. If you absolutely want your GraphQL interface to provide only mutations for each individual field you are free to create 50
Update
input types, one for each field.This PR also covers some suggestions in #324 where returns in Query types are required.
Currently:
This pull request changes that to:
So on
posts
you know you'll always get an array, and those array elements will only be of typePost
. Likewise thepost
query will always return aPost
.