Skip to content

Commit

Permalink
Less clever code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jan 15, 2025
1 parent d65d975 commit 37276a2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/cli/src/lib/schemaHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const getExistingModelName = async (name) => {
*/
export const getSchema = async (name) => {
const schema = (await getSchemaDefinitions()).datamodel

if (!name) {
return schema
}
Expand All @@ -69,10 +70,11 @@ export const getSchema = async (name) => {

const model = schema.models.find((model) => model.name === modelName)
if (!model) {
return undefined // can this happen, and if yes, should we prefer throwing an error?
// TODO: Can this happen, and if yes, should we prefer throwing an error?
return undefined
}

// look for any fields that are enums and attach the possible enum values
// Look for any fields that are enums and attach the possible enum values
// so we can put them in generated test files
model.fields.forEach((field) => {
const fieldEnum = schema.enums.find((e) => field.type === e.name)
Expand All @@ -81,8 +83,10 @@ export const getSchema = async (name) => {
}
})

// memoize based on the model name
return (schemaMemo[modelName] = model)
// Memoize based on the model name
schemaMemo[modelName] = model

return model
}

/**
Expand Down

0 comments on commit 37276a2

Please sign in to comment.