Skip to content

Commit

Permalink
Add repro for prisma/prisma#7518
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmartorell committed Jun 26, 2021
0 parents commit a5f824f
Show file tree
Hide file tree
Showing 19 changed files with 7,940 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgres://postgres:password@localhost:5432"
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: ['universe/node'],
rules: {
'import/order': [
'warn',
{
'newlines-between': 'always',
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
alphabetize: { order: 'asc' },
},
],
},
};
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build
dist

# Dependencies
node_modules
package-lock.json
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*

# Development files
.env

# macOS
.DS_Store

# Other
README.pdf

# webstorm
*.idea/*

13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"printWidth": 90,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": true,
"arrowParens": "always",
"endOfLine": "lf"
}
55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.2.cjs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nmHoistingLimits: workspaces

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-2.4.2.cjs
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Repro for issue https://github.com/prisma/prisma/issues/7518

```bash
ian@air ~/Code/ianmartorell/prisma-issue-7518 $ yarn lint
src/index.ts:19:13 - error TS2322: Type '{ product: { include: { latestUpdate: true; }; }; }' is not assignable to type 'ProductInclude'.
Object literal may only specify known properties, and 'product' does not exist in type 'ProductInclude'.

19 product: {
~~~~~~~~~~
20 include: {
~~~~~~~~~~~~~~~~~~~~~~~~
...
22 },
~~~~~~~~~~~~~~~~
23 },
~~~~~~~~~~~~~


Found 1 error.
```
32 changes: 32 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = function (api) {
api.cache(true);
return {
presets: [
['@babel/preset-typescript'],
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
plugins: [
[
'@babel/plugin-proposal-decorators',
{
legacy: true,
},
],
[
'module-resolver',
{
alias: {
'': './',
},
},
],
],
};
};
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'
services:
postgres:
image: postgres:13.1
restart: always
volumes:
- postgres:/var/lib/postgresql/data
ports:
- '5432:5432'
environment:
- POSTGRES_PASSWORD=password
container_name: postgres

volumes:
postgres:
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "prisma-issue-7518",
"version": "1.0.0",
"main": "./dist/index.js",
"scripts": {
"start": "nodemon --watch src -e '*' --exec babel-node ./src --extensions .ts -r dotenv/config",
"build": "yarn build:clean && yarn prisma:generate && yarn build:code",
"build:clean": "rimraf ./dist",
"build:code": "babel ./src --out-dir ./dist --extensions .ts,.d.ts ",
"dist": "node ./dist",
"lint": "eslint ./src --ext .ts && tsc",
"db:start": "docker-compose up -d",
"db:stop": "docker-compose down -v",
"db:reset": "prisma migrate reset",
"db:migrate": "prisma migrate dev",
"prisma:generate": "prisma generate",
"prisma:studio": "prisma studio"
},
"dependencies": {
"@prisma/client": "^2.25.0"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/eslint-parser": "^7.12.1",
"@babel/node": "^7.12.6",
"@babel/plugin-proposal-decorators": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"babel-plugin-module-resolver": "^4.1.0",
"dotenv": "^8.2.0",
"eslint": "^7.13.0",
"eslint-config-universe": "^6.0.0",
"nodemon": "^2.0.6",
"prettier": "^2.1.2",
"prisma": "^2.25.0",
"prisma-dbml-generator": "^0.6.0",
"rimraf": "^3.0.2",
"ts-node": "^9.0.0",
"typescript": "~4.1.0"
}
}
30 changes: 30 additions & 0 deletions prisma/dbml/schema.dbml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// ------------------------------------------------------
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
//// ------------------------------------------------------

Table Product {
id String [pk]
updates ProductUpdate [not null]
latestUpdateId String
latestUpdate ProductUpdate
}

Table ProductUpdate {
id String [pk]
productId String [not null]
product Product [not null]
products Product [not null]
orderItems OrderItem [not null]
}

Table OrderItem {
id String [pk]
productUpdateId String [not null]
productUpdate ProductUpdate [not null]
}

Ref: Product.latestUpdateId - ProductUpdate.id

Ref: ProductUpdate.productId > Product.id

Ref: OrderItem.productUpdateId > ProductUpdate.id
33 changes: 33 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
generator client {
provider = "prisma-client-js"
}

generator dbml {
provider = "prisma-dbml-generator"
}

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

model Product {
id String @id @default(uuid())
updates ProductUpdate[] @relation(name: "ProductUpdates")
latestUpdateId String?
latestUpdate ProductUpdate? @relation(name: "LatestProductUpdate", fields: [latestUpdateId], references: [id])
}

model ProductUpdate {
id String @id @default(uuid())
productId String
product Product @relation(name: "ProductUpdates", fields: [productId], references: [id])
products Product[] @relation(name: "LatestProductUpdate")
orderItems OrderItem[]
}

model OrderItem {
id String @id @default(uuid())
productUpdateId String
productUpdate ProductUpdate @relation(fields: [productUpdateId], references: [id])
}
3 changes: 3 additions & 0 deletions src/config/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const env = {
NODE_ENV: process.env.NODE_ENV || 'development',
};
18 changes: 18 additions & 0 deletions src/config/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PrismaClient } from '@prisma/client';

import { env } from '/src/config/globals';

let prisma: PrismaClient;

// In development we attach the prisma client to global
// to avoid creating new connections on every code reload.
if (env.NODE_ENV !== 'production') {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
} else {
prisma = new PrismaClient();
}

export { prisma };
31 changes: 31 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { prisma } from './config/prisma';

// Startup
(async function main() {
try {
prisma.orderItem.create({
data: {
productUpdate: {
create: {
product: {
create: {},
},
},
},
},
include: {
productUpdate: {
include: {
product: {
include: {
latestUpdate: true,
},
},
},
},
},
});
} catch (err) {
console.error(err.stack);
}
})();
9 changes: 9 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PrismaClient } from '@prisma/client';

declare global {
namespace NodeJS {
interface Global {
prisma: PrismaClient;
}
}
}
39 changes: 39 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"compilerOptions": {
// Basic options
"target": "ES2019",
"module": "CommonJS",
"lib": ["ESNext"],
"rootDir": "./src",
// Module resolution
"baseUrl": "./src",
"paths": {
"/src/*": ["./*"]
},
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Import non-ES modules as default imports.
"esModuleInterop": true,
// Don't emit; we're going to run ts-node directly
"noEmit": true,
// Enable strict settings like strictNullChecks & noImplicitAny.
"strict": true,
// Disallow features that require cross-file information.
"isolatedModules": true,
// Skip node_modules
"skipLibCheck": true,
// Process & infer types from .js files.
"allowJs": true,
// Linter checks
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
// Other
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
},
"exclude": ["dist"]
}

0 comments on commit a5f824f

Please sign in to comment.