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

TypeError: Cannot read property 'length' of undefined #38

Closed
Blfrg opened this issue Aug 25, 2021 · 4 comments
Closed

TypeError: Cannot read property 'length' of undefined #38

Blfrg opened this issue Aug 25, 2021 · 4 comments

Comments

@Blfrg
Copy link

Blfrg commented Aug 25, 2021

Starting with prisma version 2.29.0 to current (2.30.0);
The following error now appears when generating docs:

TypeError: Cannot read property 'length' of undefined
    at ModelGenerator.getModelDirective (/api/node_modules/prisma-docs-generator/dist/generator/model.js:196:28)
    at /api/node_modules/prisma-docs-generator/dist/generator/model.js:522:34
    at Array.map (<anonymous>)
    at ModelGenerator.getModels (/api/node_modules/prisma-docs-generator/dist/generator/model.js:518:38)
    at ModelGenerator.getData (/api/node_modules/prisma-docs-generator/dist/generator/model.js:530:26)
    at new ModelGenerator (/api/node_modules/prisma-docs-generator/dist/generator/model.js:35:26)
    at HTMLPrinter.toHTML (/api/node_modules/prisma-docs-generator/dist/printer/index.js:48:26)
    at Object.onGenerate (/api/node_modules/prisma-docs-generator/dist/index.js:51:83)
    at async LineStream.<anonymous> (/api/node_modules/@prisma/generator-helper/dist/generatorHandler.js:33:24)

Reverting back to prisma version 2.28.0 the error no longer appears.

@enixlabs
Copy link

Getting same issue even with 2.30.1

@connorjones13
Copy link

Looks like the shape of the data has changed from what this method getModelDirective is expecting.

It seems the idFields property no longer exists and instead there is property on each field called isId. Could probably update that method to iterate over the fields and do something like the below. Good PR opportunity for someone with more time than me.

for (let i = 0; i < model.fields.length; i+=1) {
    const field = model.fields[i];
    if (field.isId) {
      directiveValue.push({ name: '@@id', values: [field] });
    }
    if (field.isUnique) {
      directiveValue.push({
        name: '@@unique',
        values: [field],
      });
    }
}

example model object

{
  name: 'User',
  isEmbedded: false,
  dbName: null,
  fields: [
    {
      name: 'id',
      kind: 'scalar',
      isList: false,
      isRequired: true,
      isUnique: false,
      isId: true,
      isReadOnly: false,
      type: 'Int',
      hasDefaultValue: true,
      default: [Object],
      isGenerated: false,
      isUpdatedAt: false
    },
    {
      name: 'email',
      kind: 'scalar',
      isList: false,
      isRequired: true,
      isUnique: true,
      isId: false,
      isReadOnly: false,
      type: 'String',
      hasDefaultValue: false,
      isGenerated: false,
      isUpdatedAt: false
    },
    {
      name: 'name',
      kind: 'scalar',
      isList: false,
      isRequired: false,
      isUnique: false,
      isId: false,
      isReadOnly: false,
      type: 'String',
      hasDefaultValue: false,
      isGenerated: false,
      isUpdatedAt: false
    },
    {
      name: 'profile',
      kind: 'object',
      isList: false,
      isRequired: false,
      isUnique: false,
      isId: false,
      isReadOnly: false,
      type: 'Profile',
      hasDefaultValue: false,
      relationName: 'ProfileToUser',
      relationFromFields: [],
      relationToFields: [],
      relationOnDelete: 'SetNull',
      isGenerated: false,
      isUpdatedAt: false
    }
  ],
  isGenerated: false,
  primaryKey: null,
  uniqueFields: [],
  uniqueIndexes: []
}

@pantharshit00
Copy link
Owner

Hello

SDK had a breaking change so this will require a new release. Stay tuned, I plan to work on it this weekend.

@pantharshit00
Copy link
Owner

pantharshit00 commented Sep 24, 2021

Sorry for the delay here. This is fixed in https://github.com/pantharshit00/prisma-docs-generator/releases/tag/v0.5.0 https://www.npmjs.com/package/prisma-docs-generator/v/0.5.0

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

No branches or pull requests

4 participants