MichalLytek / MichalLytek/typegraphql-prisma

ModelsEnhance don't work

Open
#467 0 comments 0 reactions 0 assignees View on GitHub
community question
Dominant language
TypeScript
Stars
918
Forks
130
PR merge metrics
No merged PRs in 30d

Description

**Describe the issue**
I'm using apollo server, typegraphql-prisma, when I want to apply an authorize on a specific field with applyModelsEnhanceMap the change is as if it did not exist, I start the queries and I can still see the password

**Are you able to make a PR that fix this?**
```ts
import { ApolloServer, } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { PrismaClient } from '@prisma/client';

import { resolvers, ModelsEnhanceMap, applyModelsEnhanceMap, Role } from "@/../prisma/generated/type-graphql";
import { AuthChecker, Authorized, buildSchema, createMethodMiddlewareDecorator, createParameterDecorator } from "type-graphql";
import { NextRequest } from 'next/server';

const prisma = new PrismaClient();

export const authChecker: AuthChecker<{ user: { role: string } }> = ({ context: { user } }, roles) => {
return false;
};

const modelsEnhanceMap: ModelsEnhanceMap = {
User: {
fields: {
password: [Authorized("ADMIN")],
},
},
};
applyModelsEnhanceMap(modelsEnhanceMap);

const schema = await buildSchema({
resolvers,
validate: false,
authChecker,
});

const server = new ApolloServer({
schema
});
const nextHandlerPromise = startServerAndCreateNextHandler(server, {
context: async () => ({ user: { id: "cm0wf7tkb0000yi5cjb7lrwrv", role: Role.USER }, prisma }),
})

const handler = async (req: NextRequest) => {
const nextHandler = await nextHandlerPromise;
return nextHandler(req);
};

export { handler as GET, handler as POST };
```
**Additional context**
I tried to do the same with applyResolversEnhanceMap on the entire model and it works perfectly

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the supplied Apollo Server, Next.js, TypeGraphQL, and Prisma setup, focusing on applyModelsEnhanceMap for the User.password field and the generated type-graphql resolvers. Compare its behavior with applyResolversEnhanceMap, then verify that unauthorized queries no longer expose password while the existing schema still builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, authorization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.