prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

`findMany` fails with RequestError ECONNREFUSED #237

Closed nikolasburk closed 5 years ago

nikolasburk commented 5 years ago

This is my Prisma schema:

datasource db {
  provider = "sqlite"
  url      = "file:./northwind.db"
}

generator photon {
  provider = "photonjs"
}

model Category {
  category_id  Int       @id
  categoryName String    @map("category_name")
  description  String?
  products     Product[]

  @@map("categories")
}

model Customer {
  customer_id  String  @default(cuid()) @id
  companyName  String  @map("company_name")
  contactName  String? @map("contact_name")
  contactTitle String? @map("contact_title")
  address      String?
  city         String?
  region       String?
  postalCode   String? @map("postal_code")
  country      String?
  phone        String?
  fax          String?

  orders Order[]

  @@map("customers")
}

model CustomerDemographic {
  customer_type_id String  @default(cuid()) @id
  customerDesc     String? @map("customer_desc")

  @@map("customer_demographics")
}

model Employee {
  employee_id         Int                 @id
  address             String?
  birthDate           DateTime?           @map("birth_date")
  city                String?
  country             String?
  employeeTerritories EmployeeTerritory[]
  extension           String?
  firstName           String              @map("first_name")
  hireDate            DateTime?           @map("hire_date")
  homePhone           String?             @map("home_phone")
  lastName            String              @map("last_name")
  notes               String?
  orders              Order[]
  photoPath           String?             @map("photo_path")
  postalCode          String?             @map("postal_code")
  region              String?
  title               String?
  titleOfCourtesy     String?             @map("title_of_courtesy")

  @@map("employees")
}

model EmployeeTerritory {
  order_id Int @id

  employee  Employee  @map("employee_id")
  territory Territory @map("territory_id")

  @@map("employee_territories")
}

model Order {
  order_id       Int       @id
  customer       Customer? @map("customer_id")
  employee       Employee? @map("employee_id")
  freight        Float?
  orderDate      DateTime? @map("order_date")
  requiredDate   DateTime? @map("required_date")
  shipAddress    String?   @map("ship_address")
  shipCity       String?   @map("ship_city")
  shipCountry    String?   @map("ship_country")
  shipName       String?   @map("ship_name")
  shippedDate    DateTime? @map("shipped_date")
  shipPostalCode String?   @map("ship_postal_code")
  shipRegion     String?   @map("ship_region")
  shipVia        Shipper?  @map("ship_via")

  @@map("orders")
}

model Product {
  product_id      Int       @id
  category        Category? @map("category_id")
  discontinued    Int
  productName     String    @map("product_name")
  quantityPerUnit String?   @map("quantity_per_unit")
  reorderLevel    Int?      @map("reorder_level")
  supplier        Supplier? @map("supplier_id")
  unitPrice       Float?    @map("unit_price")
  unitsInStock    Int?      @map("units_in_stock")
  unitsOnOrder    Int?      @map("units_on_order")

  @@map("products")
}

model Region {
  region_id         Int         @id
  regionDescription String      @map("region_description")
  territories       Territory[]

  @@map("region")
}

model Shipper {
  shipper_id  Int     @id
  companyName String  @map("company_name")
  orders      Order[]
  phone       String?

  @@map("shippers")
}

model Supplier {
  supplier_id  Int       @id
  address      String?
  city         String?
  companyName  String    @map("company_name")
  contactName  String?   @map("contact_name")
  contactTitle String?   @map("contact_title")
  country      String?
  fax          String?
  homepage     String?
  phone        String?
  postalCode   String?   @map("postal_code")
  products     Product[]
  region       String?

  @@map("suppliers")
}

model Territory {
  territory_id         String              @default(cuid()) @id
  employeeTerritories  EmployeeTerritory[]
  region               Region              @map("region_id")
  territoryDescription String              @map("territory_description")

  @@map("territories")
}

model UsState {
  state_id    Int     @id
  stateAbbr   String? @map("state_abbr")
  stateName   String? @map("state_name")
  stateRegion String? @map("state_region")

  @@map("us_states")
}

I generated Photon.js based on this script with prisma2 generate.

Here is my script.ts;

import { Photon } from '@generated/photon'

const photon = new Photon({
  debug: true
})

async function main(){

  const allEmployees = await photon.employees.findMany()
  console.log(allEmployees)

}

main()

Here's the error message including debug info that I see when running the script:

$ yarn start
yarn run v1.17.3
$ ts-node script.ts
  getos { platform: 'darwin', libssl: undefined } +0ms
  photon Request: +0ms
  photon query {
  photon   findManyEmployee {
  photon     employee_id
  photon     address
  photon     birthDate
  photon     city
  photon     country
  photon     extension
  photon     firstName
  photon     hireDate
  photon     homePhone
  photon     lastName
  photon     notes
  photon     photoPath
  photon     postalCode
  photon     region
  photon     title
  photon     titleOfCourtesy
  photon   }
  photon } +0ms
  engine {
  engine   PRISMA_DML: 'datasource db {\n  provider = "sqlite"\n  url      = "file:./northwind.db"\n}\n' +
  engine     '\ngenerator photon {\n  provider = "photonjs"\n}\n\n\nmodel Category {\n  ' +
  engine     'category_id  Int       @id\n  categoryName String    @map("category_name")\n ' +
  engine     ' description  String?\n  products     Product[]\n\n  @@map("categories")\n}\n\n' +
  engine     'model Customer {\n  customer_id  String  @default(cuid()) @id\n  companyName ' +
  engine     ' String  @map("company_name")\n  contactName  String? @map("contact_name")\n ' +
  engine     ' contactTitle String? @map("contact_title")\n  address      String?\n  city  ' +
  engine     '       String?\n  region       String?\n  postalCode   String? ' +
  engine     '@map("postal_code")\n  country      String?\n  phone        String?\n  fax    ' +
  engine     '      String?\n\n  orders Order[]\n\n  @@map("customers")\n}\n\nmodel ' +
  engine     'CustomerDemographic {\n  customer_type_id String  @default(cuid()) @id\n  ' +
  engine     'customerDesc     String? @map("customer_desc")\n\n  ' +
  engine     '@@map("customer_demographics")\n}\n\nmodel Employee {\n  employee_id         ' +
  engine     'Int                 @id\n  address             String?\n  birthDate          ' +
  engine     ' DateTime?           @map("birth_date")\n  city                String?\n  ' +
  engine     'country             String?\n  employeeTerritories EmployeeTerritory[]\n  ' +
  engine     'extension           String?\n  firstName           String              ' +
  engine     '@map("first_name")\n  hireDate            DateTime?           ' +
  engine     '@map("hire_date")\n  homePhone           String?             ' +
  engine     '@map("home_phone")\n  lastName            String              ' +
  engine     '@map("last_name")\n  notes               String?\n  orders              ' +
  engine     'Order[]\n  photoPath           String?             @map("photo_path")\n  ' +
  engine     'postalCode          String?             @map("postal_code")\n  region       ' +
  engine     '       String?\n  title               String?\n  titleOfCourtesy     String? ' +
  engine     '            @map("title_of_courtesy")\n\n  @@map("employees")\n}\n\nmodel ' +
  engine     'EmployeeTerritory {\n  order_id Int @id\n\n  employee  Employee  ' +
  engine     '@map("employee_id")\n  territory Territory @map("territory_id")\n\n  ' +
  engine     '@@map("employee_territories")\n}\n\nmodel Order {\n  order_id       Int       ' +
  engine     '@id\n  customer       Customer? @map("customer_id")\n  employee       ' +
  engine     'Employee? @map("employee_id")\n  freight        Float?\n  orderDate      ' +
  engine     'DateTime? @map("order_date")\n  requiredDate   DateTime? ' +
  engine     '@map("required_date")\n  shipAddress    String?   @map("ship_address")\n  ' +
  engine     'shipCity       String?   @map("ship_city")\n  shipCountry    String?   ' +
  engine     '@map("ship_country")\n  shipName       String?   @map("ship_name")\n  ' +
  engine     'shippedDate    DateTime? @map("shipped_date")\n  shipPostalCode String?   ' +
  engine     '@map("ship_postal_code")\n  shipRegion     String?   @map("ship_region")\n  ' +
  engine     'shipVia        Shipper?  @map("ship_via")\n\n  @@map("orders")\n}\n\nmodel ' +
  engine     'Product {\n  product_id      Int       @id\n  category        Category? ' +
  engine     '@map("category_id")\n  discontinued    Int\n  productName     String    ' +
  engine     '@map("product_name")\n  quantityPerUnit String?   @map("quantity_per_unit")\n' +
  engine     '  reorderLevel    Int?      @map("reorder_level")\n  supplier        ' +
  engine     'Supplier? @map("supplier_id")\n  unitPrice       Float?    ' +
  engine     '@map("unit_price")\n  unitsInStock    Int?      @map("units_in_stock")\n  ' +
  engine     'unitsOnOrder    Int?      @map("units_on_order")\n\n  @@map("products")\n}\n\n' +
  engine     'model Region {\n  region_id         Int         @id\n  regionDescription ' +
  engine     'String      @map("region_description")\n  territories       Territory[]\n\n  ' +
  engine     '@@map("region")\n}\n\nmodel Shipper {\n  shipper_id  Int     @id\n  companyName ' +
  engine     'String  @map("company_name")\n  orders      Order[]\n  phone       String?\n\n ' +
  engine     ' @@map("shippers")\n}\n\nmodel Supplier {\n  supplier_id  Int       @id\n  ' +
  engine     'address      String?\n  city         String?\n  companyName  String    ' +
  engine     '@map("company_name")\n  contactName  String?   @map("contact_name")\n  ' +
  engine     'contactTitle String?   @map("contact_title")\n  country      String?\n  fax  ' +
  engine     '        String?\n  homepage     String?\n  phone        String?\n  postalCode ' +
  engine     '  String?   @map("postal_code")\n  products     Product[]\n  region       ' +
  engine     'String?\n\n  @@map("suppliers")\n}\n\nmodel Territory {\n  territory_id         ' +
  engine     'String              @default(cuid()) @id\n  employeeTerritories  ' +
  engine     'EmployeeTerritory[]\n  region               Region              ' +
  engine     '@map("region_id")\n  territoryDescription String              ' +
  engine     '@map("territory_description")\n\n  @@map("territories")\n}\n\nmodel UsState {\n  ' +
  engine     'state_id    Int     @id\n  stateAbbr   String? @map("state_abbr")\n  ' +
  engine     'stateName   String? @map("state_name")\n  stateRegion String? ' +
  engine     '@map("state_region")\n\n  @@map("us_states")\n}',
  engine   PORT: '54073',
  engine   RUST_BACKTRACE: '1',
  engine   RUST_LOG: 'info',
  engine   OVERWRITE_DATASOURCES: '[{"name":"db","url":"file:/Users/nikolasburk/Desktop/introspection/sqlite-northwind/northwind.db"}]'
  engine } +0ms
  engine { cwd: '/Users/nikolasburk/Desktop/introspection/sqlite-northwind' } +5ms
  engine:log {
  engine:log   message: 'Starting 8 workers',
  engine:log   level: 'info',
  engine:log   application: 'prisma',
  engine:log   date: 2019-09-27T10:36:05.325Z
  engine:log } +0ms
  engine:log {
  engine:log   message: 'Starting server on 0.0.0.0:54073',
  engine:log   level: 'info',
  engine:log   application: 'prisma',
  engine:log   date: 2019-09-27T10:36:05.326Z
  engine:log } +0ms
  engine:log {
  engine:log   message: 'Started http server on 0.0.0.0:54073',
  engine:log   level: 'info',
  engine:log   application: 'prisma',
  engine:log   date: 2019-09-27T10:36:05.327Z
  engine:log } +0ms
  engine Ready after try number 0 +74ms
(node:61387) UnhandledPromiseRejectionWarning: Error: 
Invalid `const allEmployees = await photon.employees.findMany()` invocation in /Users/nikolasburk/Desktop/introspection/sqlite-northwind/script.ts:9:47

   5 })
   6 
   7 async function main(){
   8 
→  9   const allEmployees = await photon.employees.findMany(

Reason: {
  "name": "RequestError",
  "code": "ECONNREFUSED",
  "host": "localhost:54073",
  "hostname": "localhost",
  "method": "POST",
  "path": "/",
  "protocol": "http:",
  "url": "http://localhost:54073/",
  "gotOptions": {
    "path": "/",
    "protocol": "http:",
    "slashes": true,
    "auth": null,
    "host": "localhost:54073",
    "port": "54073",
    "hostname": "localhost",
    "hash": null,
    "search": null,
    "query": null,
    "pathname": "/",
    "href": "http://localhost:54073/",
    "retry": {
      "methods": {},
      "statusCodes": {},
      "errorCodes": {}
    },
    "headers": {
      "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
      "content-type": "application/json",
      "accept": "application/json",
      "accept-encoding": "gzip, deflate",
      "content-length": 291
    },
    "hooks": {
      "beforeRequest": [],
      "beforeRedirect": [],
      "beforeRetry": [],
      "afterResponse": [],
      "beforeError": [],
      "init": []
    },
    "decompress": true,
    "throwHttpErrors": true,
    "followRedirect": true,
    "stream": false,
    "form": false,
    "json": true,
    "cache": false,
    "useElectronNet": false,
    "body": "{\"query\":\"query {\\n  findManyEmployee {\\n    employee_id\\n    address\\n    birthDate\\n    city\\n    country\\n    extension\\n    firstName\\n    hireDate\\n    homePhone\\n    lastName\\n    notes\\n    photoPath\\n    postalCode\\n    region\\n    title\\n    titleOfCourtesy\\n  }\\n}\",\"variables\":{}}",
    "method": "POST",
    "forceRefresh": true
  }
}

    at PhotonFetcher.<anonymous> (/Users/nikolasburk/Desktop/introspection/sqlite-northwind/node_modules/@generated/photon/index.js:46:27)
    at Generator.throw (<anonymous>)
    at rejected (/Users/nikolasburk/Desktop/introspection/sqlite-northwind/node_modules/@generated/photon/index.js:5:65)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:61387) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:61387) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
✨  Done in 4.05s.

Note that I'm using this SQLite DB file: northwind.db.zip

timsuchanek commented 5 years ago

Which prisma2 version are you using?

nikolasburk commented 5 years ago

This error occured with preview-12. Just upgraded to preview-13 and regenerated Photon, now it works 👌