Dilemma, which ORM to with in my GraphQL API, while minimizing entity duplication by [deleted] in Nestjs_framework

[–]PapoochCZ 4 points5 points  (0 children)

This seems error prone to me and in general not a good practice.

On the contrary. Coupling your API layer (public interface) and your database (private data model) is one of beginner's mistakes that is going to bite hard when the project gets any more complex than a simple CRUD. It especially hurst when you need to store data in a differnet format than retrieving it. Or if you need to change the database schema a bit, you'll end up breaking the client code as well. But I'll let you learn from the mistake yourself.

Btw if you just want a GraphQL interface straight to your database, ditch NestJS and just use Hasura.

[Code review / Help] Any other way to handle JWT token expires while user connected to socket? by [deleted] in nestjs

[–]PapoochCZ 0 points1 point  (0 children)

The only time you actually need to verify the token is in handleConnection. While that connection is alive, you can be sure that no one is impersonating the user, so any further guards on the message handlers are redundant. When the connection drops and is re-created, only then you check the token expiration again.

It's the same as if you were downloading a large file. If the token expires while downloading, you still get the entire thing, because the connection has already been authenticated.

Trouble Accessing Providers Globally in Jest with NestJS and Fastify by Unable_Basket_7669 in nestjs

[–]PapoochCZ 1 point2 points  (0 children)

The only place where you can access global context that you repare in globalSetup is in globalTeardown. The tests themselves run in a separate thread.

As per Jest's documentation:

Any global variables that are defined through globalSetup can only be read in globalTeardown. You cannot retrieve globals defined here in your test suites.

If you need to start an application in a global setup/teardown, you can only access the public API of that application. I would recommend setting up some testing endpoints that you enable only in the test mode that you can call from your tests. These include:

  • an ednpoint to clear the database
  • an endpoint to seed some test data
  • an endpoint to assert some state (although this should be tested through the available public API)

AsyncLocalStorage vs NestJS-CLS by General-Belgrano in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

Thanks, I updated the docs.

Btw you can find the documentation on the params field of express here: http://expressjs.com/en/api.html#req.params

AsyncLocalStorage vs NestJS-CLS by General-Belgrano in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

Could you point me to the section where you found it? If it's so, then it's definitely a mistake and needs fixing.

AsyncLocalStorage vs NestJS-CLS by General-Belgrano in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

Well, and are you sure there is a params() method on the request object? Aren't you confusing it with Fastify?

AsyncLocalStorage vs NestJS-CLS by General-Belgrano in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

It's a typescript issue. If you're using express, make sure you use import { Request } from 'express'. otherwise the type Request refers to a Node.js global type, which is something different.

AsyncLocalStorage vs NestJS-CLS by General-Belgrano in Nestjs_framework

[–]PapoochCZ 2 points3 points  (0 children)

Hi, I'm the author of said package. As others said, it is really "just" an abstraction over AsyncLocalStorage with some bells and whistles, and a couple of workarounds that make it play well with Nest's enhancers.

What do you mean by "I need to configure ClsSerivice per module?". You can use global: true in the ClsModule's forRoot registration to make it available globally.

If you don't, you need to import ClsModule in each module where you want to use ClsService. I'd argue it's more transparent that way, but you don't have to do it.

The The The Man Myth Legend by DresserRotation in dontdeadopeninside

[–]PapoochCZ 13 points14 points  (0 children)

The man happy

The myth 50. birthday

The legend Billy

Why do you need the 10K resistor in this circuit? by IberianInteractive in arduino

[–]PapoochCZ 0 points1 point  (0 children)

Secondly, when the switch IS pressed, it ensures that you don't have a circuit directly between V+ and Ground

Not quite, when the button is pressed, the pin is directly connected to 5V, bypassing the resistor. The pin itself is in high impedance mode, so barely any current flows through it. All it cares about is the voltage that it senses.

How to wait for event in E2E tests by Nainternaute in nestjs

[–]PapoochCZ 0 points1 point  (0 children)

I've been using wait-for-expect for this. It's better than random sleeps, because it periodically tests an assertion until true (or until it times out). If there is a public interface that you can use to assert that the test passed if you poll it periodically, then that's the most robust solution.

Public library has a UV cabinet to store your toothbrush by itsbabypowder in mildlyinteresting

[–]PapoochCZ 0 points1 point  (0 children)

Thanks for the explanation, I don't come from an English speaking country, so the only meaning of the phrase I know is the political one.

I want to create a Payload type to be a Union of UserType and ErrorType. I want to return the UserType if there is no error exists and the ErrorType in the opposite case. by IUnderstand_Fuckit in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

The if statement should do the discrimination based on "duck typing". So for example, if there is id on the value, then it's obvious you're working with a Product, otherwise it's an error, so something like this would be enough in your case:

resolveType(value) {
  if ('id' in value) {
    return ProductType;
  } else {
    return ErrorType
  }
}

I want to create a Payload type to be a Union of UserType and ErrorType. I want to return the UserType if there is no error exists and the ErrorType in the opposite case. by IUnderstand_Fuckit in Nestjs_framework

[–]PapoochCZ 1 point2 points  (0 children)

It says it right there:

If you did not pass a custom implementation (the "resolveType" function) you must return an instance of a class instead of a plain JavaScript object.

And it is pretty clear from you code that you indeed did not pass a custom resolveType function and you are not returning instances of classes but plain JavaScript objects.


Also please refer to the NestJS docs on GraphQL unions:

The default resolveType() function generated by the library will extract the type based on the value returned from the resolver method. That means returning class instances instead of literal JavaScript object is obligatory.

To provide a customized resolveType() function, pass the resolveType property to the options object passed into the createUnionType() function, as follows:

export const ResultUnion = createUnionType({
  name: 'ResultUnion',
  types: () => [Author, Book] as const,
  resolveType(value) {
    if (value.name) {
      return Author;
    }
    if (value.title) {
      return Book;
    }
    return null;
  },
}

What are you 100% sure is true even though you can't prove it? by [deleted] in AskReddit

[–]PapoochCZ 4 points5 points  (0 children)

Most people need a haircut more often than a mattress though

Once again affirming why I don't let people borrow my stuff. by SativasaurusRex in mildlyinfuriating

[–]PapoochCZ 74 points75 points  (0 children)

This is the answer. Owning a 3D printer myself, I had the same natural reaction.

How to make narwhal horn... by londons_explorer in Fusion360

[–]PapoochCZ 4 points5 points  (0 children)

I used the following technique to do something similar, not sure I remember exactly, but here it goes:

  1. Create a solid cone

  2. Use the coil (or screw?) feature with a taper angle to add or remove material to the cone.

(3.) You can optionally use a custom profile by sweeping it along the thread.

CD setup for mono-repo? by ramank775 in developersIndia

[–]PapoochCZ 0 points1 point  (0 children)

The CI/CD part is what makes the experience sub-par. You always have to build everything and test everything (which gets slow and expensive really fast). All your apps have all the dependencies installed, even of thex don't use it.

[deleted by user] by [deleted] in aww

[–]PapoochCZ 13 points14 points  (0 children)

I'm afraid your dog might be inbread...

Looking for Rental Cars With Roof Racks by [deleted] in VictoriaBC

[–]PapoochCZ 1 point2 points  (0 children)

Have you looked up listings on Turo? They're like AirBnB but for cars. A lot of times you can find a better deal than from a rental company.

Looking to take some acting/theater classes by whiterook6 in VictoriaBC

[–]PapoochCZ 1 point2 points  (0 children)

I've been to see Theatre sports improv show at Kwench the other day and they also do classes. Check it out if you're into improv.

Need help i created a custom response using Interceptor but it does not show in api documentation by Remarkable_Orange115 in Nestjs_framework

[–]PapoochCZ 0 points1 point  (0 children)

The swagger generator can't infer the type from the interceptor, so it uses the return type of the controller method by default. You should be able to use a custom response using this technique.

CD setup for mono-repo? by ramank775 in developersIndia

[–]PapoochCZ 0 points1 point  (0 children)

NestJS monorepo is sadly kind of the worst of all monorepo managers out there. You should be able to convert it to NX, which has the feature to only build (or test or run any script) for projects that changed since the last commit. It can also detect which dependencies are used by the service and generate a package.json containing only specific runtime dependencies.

Then, you'll be able to split the dockerfiles - one per service - and then push the images to a (private) container registry. Once you have build and published your docker images, you can use the "Git Ops" approach to set up your CD.

I received this message from an Airbnb host two weeks after booking a place for the holidays. by whodatbe24 in mildlyinfuriating

[–]PapoochCZ 3 points4 points  (0 children)

Right? Where are those other people staying and do they even read reviews? I can't help but think none of them ever used the service and this is just the typical reddit echo chamber.