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

Keystone generating 2 different relationship schemas for exact same list code, and one doesn't appear in the other related list as a field. #9303

Open
jj-matos opened this issue Aug 22, 2024 · 1 comment
Assignees
Labels
🐛 bug Unresolved bug

Comments

@jj-matos
Copy link

jj-matos commented Aug 22, 2024

I have 2 lists with exactly the same fields and code, just different names. I have set them to only appear on item view of the list [videoObject] when they are not null. What happens is that one of them (Legacy_Video), never appears. I checked the item variable of the [videoObject] and legacyvideoID never appears (null or with a value), and xrvideoID always appears.

As you can see by the code there is no reason for them to have different behaviours, and there is no reason for [Legacy_Video] not showing as a field of [videoObject] list. What is hapening with [videoObject] is also happening with another list [videoCastCredits] which has the exact same logic, in relationship with [XR_Video] and [Legacy_Video]. So it must be something related with [Legacy_Video] list, although the code is exaclty the same as [XR_Video], that appears.

I tried everything:

  • deleted .keystone folder
  • deleted node_modules
  • deleted schema.graphql
  • deleted schema.prisma
  • deleted migrations folder
  • cleaned yarn cache
  • deleted database
  • created database with a different name
  • reinstalled yarn

Each time I do yarn install, I get an error in the end for not having schema.prisma. I then do yarn run dev and it generates everything, but the schemas that should be the same come always different and [Legacy_Video] never appears in the ui or the [item] object variable of [videoObject]. I tried it several times. It's always the same.

I wonder if there is any kind of cache that is storing some old schema, that i don't know about.

keystone generated schema.prisma:

model Legacy_Video {
  id                      String                @id @default(cuid())
  about                   String                @default("")
  performanceOrRehearsal  String
  Languages               String?
  date                    String?
  castCredits             Video_CastAndCredits? @relation("Legacy_Video_castCredits", fields: [castCreditsId], references: [id])
  castCreditsId           String?               @unique @map("castCredits")
  videoObject             VideoObject?          @relation("Legacy_Video_videoObject", fields: [videoObjectId], references: [id])
  videoObjectId           String?               @unique @map("videoObject")
  dataStatus              String
  approved                Boolean               @default(false)
  streamingUrl            String                @default("")
  dataUrl                 String                @default("")
  creativeWork            CreativeWork?         @relation("Legacy_Video_creativeWork", fields: [creativeWorkId], references: [id])
  creativeWorkId          String?               @map("creativeWork")
  associatedPersons       Person[]              @relation("Legacy_Video_associatedPersons")
  associatedOrganizations Organization[]        @relation("Legacy_Video_associatedOrganizations")

  @@index([creativeWorkId])
}

model _ {
  id                      String                @id @default(cuid())
  about                   String                @default("")
  performanceOrRehearsal  String
  Languages               String?
  date                    String?
  castCredits             Video_CastAndCredits? @relation("Video_CastAndCredits_xrVideo")
  videoObject             VideoObject?          @relation("VideoObject_xrVideo")
  dataStatus              String
  approved                Boolean               @default(false)
  streamingUrl            String                @default("")
  dataUrl                 String                @default("")
  creativeWork            CreativeWork?         @relation("XR_Video_creativeWork", fields: [creativeWorkId], references: [id])
  creativeWorkId          String?               @map("creativeWork")
  associatedPersons       Person[]              @relation("Person_xrVideo")
  associatedOrganizations Organization[]        @relation("Organization_xrVideo")

  @@index([creativeWorkId])
}

in [videoObject] list:

...group({
      label: "Related To:", 
      fields: {   
        xrVideo: relationship({
          label: 'XR Video',
          ref: 'XR_Video.videoObject',
          many: false, 
          ui: {
            createView: {
              fieldMode: ({ session, context }) => 'hidden',
            },
            itemView: {
              fieldMode: async ({ session, context, item }) => {
                console.log('ITEM XR:')
                console.log(item)

                if (item.xrVideoId != null) return 'read'

                return 'hidden'
              },
              fieldPosition: 'sidebar',          
            },
            listView: {
              fieldMode: ({ session, context }) => 'read',
            },        
          }       
        }),                    
        legacyVideo: relationship({
    	  label: 'Legacy Video',
    	  ref: 'Legacy_Video.videoObject',
          many: false, 
          ui: {
            createView: {
              fieldMode: ({ session, context }) => 'hidden',
            },
            itemView: {
              fieldMode: async ({ session, context, item }) => {
                console.log('ITEM LEGACY:')
                console.log(item)

                if (item.legacyVideoId != null) return 'read'

                return 'hidden'
              },
              fieldPosition: 'sidebar',          
            },
            listView: {
              fieldMode: ({ session, context }) => 'read',
            },        
          }       
    		}),
      }
    }),

in Legacy_Video list (same as XR_Video):

export const Legacy_Video = list({
  ...
  fields:{          
    ...
    castCredits: relationship({
      label:"Cast & Credits",
      ref: 'Video_CastAndCredits.legacyVideo', 
      many: false,         
    }),    
    
    videoObject: relationship({
      label: 'Video Object',
      ref: 'VideoObject.legacyVideo', 
      many: false, 
    }),  
    
    ...
    

The prisma schema of both [XR_Video] and [Legacy_Video] should be exactly the same. And [Legacy_Video] should appear as a field of videoObject. But both don't occur.

Using debian 12, node v18.19.0

Grateful for your help.

@jj-matos jj-matos changed the title Generating different schemas for exact same list code, and one doesn't appear in another list as relationship, as it should. Keystone generating 2 different relationship schemas for exact same list code, and one doesn't appear in the other related list as a field. Aug 27, 2024
@molomby
Copy link
Member

molomby commented Aug 31, 2024

I've verified this with a simplified example:

export const lists = {
  videoObject: list({
    access: allowAll,
    fields: {
      name: text(),
      legacyVideo: relationship({ ref: 'legacyVideo.videoObject', many: false }),
      xrVideo: relationship({ ref: 'xrVideo.videoObject', many: false }),
    },
  }),
  legacyVideo: list({
    access: allowAll,
    fields: {
      name: text(),
      videoObject: relationship({ ref: 'videoObject.legacyVideo', many: false }),
    },
  }),
  xrVideo: list({
    access: allowAll,
    fields: {
      name: text(),
      videoObject: relationship({ ref: 'videoObject.xrVideo', many: false }),
    },
  }),
} satisfies Lists;

Produces:

model videoObject {
  id          String       @id @default(cuid())
  name        String       @default("")
  legacyVideo legacyVideo? @relation("legacyVideo_videoObject")
  xrVideo     xrVideo?     @relation("videoObject_xrVideo", fields: [xrVideoId], references: [id])
  xrVideoId   String?      @unique @map("xrVideo")
}

model legacyVideo {
  id            String       @id @default(cuid())
  name          String       @default("")
  videoObject   videoObject? @relation("legacyVideo_videoObject", fields: [videoObjectId], references: [id])
  videoObjectId String?      @unique @map("videoObject")
}

model xrVideo {
  id          String       @id @default(cuid())
  name        String       @default("")
  videoObject videoObject? @relation("videoObject_xrVideo")
}

And a DB (SQLite) schema of:

CREATE TABLE IF NOT EXISTS "videoObject" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL DEFAULT '',
    "xrVideo" TEXT,
    CONSTRAINT "videoObject_xrVideo_fkey" FOREIGN KEY ("xrVideo") REFERENCES "xrVideo" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
CREATE UNIQUE INDEX "videoObject_xrVideo_key" ON "videoObject"("xrVideo");

CREATE TABLE IF NOT EXISTS "legacyVideo" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL DEFAULT '',
    "videoObject" TEXT,
    CONSTRAINT "legacyVideo_videoObject_fkey" FOREIGN KEY ("videoObject") REFERENCES "videoObject" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
CREATE UNIQUE INDEX "legacyVideo_videoObject_key" ON "legacyVideo"("videoObject");

CREATE TABLE IF NOT EXISTS "xrVideo" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL DEFAULT ''
);

Clearly this isn't correct – the videoObject column is totally missing from xrVideo. I see no reason this config shouldn't be valid. Is there some limitation on the number of one-to-one relationships that exist on a list?

@dcousens dcousens self-assigned this Aug 31, 2024
@dcousens dcousens added the 🐛 bug Unresolved bug label Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unresolved bug
Projects
None yet
Development

No branches or pull requests

3 participants