ps73 / feathers-prisma

A Feathers service adapter for Prisma ORM.
MIT License
38 stars 3 forks source link

Can't get $select, $sort, or $in to work via html request #14

Closed robblovell closed 1 year ago

robblovell commented 1 year ago

Steps to reproduce

I have created a basic feathers controller using this feathers-prisma adapter and have tried to use various query parameters with no success. I have tried various queries:

$select

The official feathers.js documentation says this should work, but:

trying: http://127.0.0.1:5057/spaces?$select[]=organization_id,$select[]=space_id
gives error: "Invalid query parameter $select[]"

Looking through the code, it looks like the "[]" is not seen, so removing that gets us farther, but still have an error:

trying: http://127.0.0.1:5057/spaces?$select=organization_id,$select=space_id
gives error: "$select.forEach is not a function"

The query $select value didn't get converted to an array... Am I missing something?

$sort

$sort via the official feathers documentation:

trying: http://127.0.0.1:5057/spaces?$limit=2&$sort[created_at]=-1
gives error: "Invalid query parameter $sort[created_at]"

$in

trying: 127.0.0.1:5057/spaces?organization_id[$in][]=60230961c459f31c3883c1f0&organization_id[$in][]=60230961c459f31c3883c1df
gives the error: Invalid `this.Model.findMany() ...
trying: 127.0.0.1:5057/spaces?organization_id[$in]=60230961c459f31c3883c1f0&organization_id[$in]=60230961c459f31c3883c1df
gives the error: Invalid `this.Model.findMany() ...

spaces.class.ts

import { PrismaService, PrismaServiceOptions } from 'feathers-prisma';
import { Application } from '../../declarations';

interface Options extends PrismaServiceOptions {}

export class Spaces extends PrismaService {
  //eslint-disable-next-line @typescript-eslint/no-unused-vars
  constructor(options: Options, app: Application) {
    super(options, app.get('prisma'));
  }
}

spaces.service.ts

mport { ServiceAddons } from '@feathersjs/feathers';
import { Application } from '../../declarations';
import { Spaces } from './spaces.class';
import hooks from './spaces.hooks';

// Add this service to the service type index
declare module '../../declarations' {
  interface ServiceTypes {
    'spaces': Spaces & ServiceAddons<any>;
  }
}

export default function (app: Application): void {
  const options = {
    model: 'spaces',
    client: app.get('prisma'),
    paginate: app.get('paginate')
  };

  // Initialize our service with any options it requires
  app.use('/spaces', new Spaces(options, app));

  // Get our initialized service so that we can register hooks
  const service = app.service('spaces');

  service.hooks(hooks);
}

prisma model

model spaces {
  space_id          Int       @id @default(autoincrement())
  name              String?   @db.VarChar
  created_at        DateTime? @db.Timestamptz(6)
  description       String?
  organization_id   String?   @db.VarChar
  primary_color     String?   @db.VarChar
  secondary_color   String?   @db.VarChar

  @@index([organization_id], map: "spaces_link_organization_id_index")
}

Expected behavior

$select

Should select return only the organization_id and space_id's for the records.

$sort

Should sort by created_at descending

$in

Should return the records with the ids in the given array of ids.

Actual behavior

Errors: Invalid query parameter, $select.forEach is not a function, or Invalidthis.Model.findMany() ...`

System configuration

Tell us about the applicable parts of your setup.

This is a bare bones feather setup with no hooks. Using feathersjs-serverless.

Module versions (especially the part that's not working):

"dependencies": {
    "@feathersjs/configuration": "^4.5.15",
    "@feathersjs/errors": "^4.5.15",
    "@feathersjs/express": "^4.5.15",
    "@feathersjs/feathers": "^4.5.15",
    "@feathersjs/primus": "^4.5.15",
    "@feathersjs/socketio": "^4.5.15",
    "@feathersjs/transport-commons": "^4.5.15",
    "@prisma/client": "^3.15.2",
    "aws-serverless-express": "^3.4.0",
    "body-parser": "^1.20.1",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "ejs": "^3.1.8",
    "express": "^4.18.2",
    "feathersjs-serverless": "^0.3.1",
    "feathers-prisma": "^0.6.0",
    "helmet": "^5.1.1",
    "install": "^0.13.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.7",
    "serve-favicon": "^2.5.0",
    "serverless-express": "^2.0.12",
    "serverless-http": "^3.1.0",
    "winston": "^3.8.2",
    "ws": "^8.11.0"
  },

NodeJS version: v16.18.0

Operating System: OS/X M1

Browser Version: Firefox, Chrome, Safari

React Native Version: N/A

Module Loader: N/A

robblovell commented 1 year ago

I started it up as a pure express/feathers.js app not as a "feathersjs-serverless" app and it seems to behave correctly. There might be some nastiness around parsing query parameters when that module is in between the adapter, feathers and the request coming in.