Is it possible to use nexus-prisma with nestjs? Ha...
# random
m
Is it possible to use nexus-prisma with nestjs? Has anyone tried it yet?
h
You can do that like so
Copy code
import { Injectable, Logger } from '@nestjs/common';
import { GqlOptionsFactory, GqlModuleOptions } from '@nestjs/graphql';
import { makeSchema } from 'nexus';

@Injectable()
export class GraphqlConfigService implements GqlOptionsFactory {
  async createGqlOptions(): Promise<GqlModuleOptions> {
   const schema = makeSchema({
  types: [Account, Node, Query, StatusEnum],
  // or types: { Account, Node, Query }
  // or types: [Account, [Node], { Query }]
});

    return {
      debug: true,
      playground: true,
      schema,
    };
  }
}
And then in the app.module...
Copy code
imports: [
    GraphQLModule.forRootAsync({
      useClass: GraphqlConfigService,
    }),
  ],
✔️ 1
prisma green 1
m
Awesome thanks 🙂 I will try it out now
🙂 1
Copy code
import { Injectable } from '@nestjs/common';
import { GqlOptionsFactory, GqlModuleOptions } from '@nestjs/graphql';
import { makePrismaSchema, prismaObjectType } from 'nexus-prisma';
import * as path from 'path';
import { prisma } from './client';
import datamodelInfo from './nexus/datamodel-info';

@Injectable()
export class GraphqlConfigService implements GqlOptionsFactory {
    async createGqlOptions(): Promise<GqlModuleOptions> {

        const Query = prismaObjectType({
            name: 'Query',
            definition(t) {
                t.prismaFields(['*'])
            }
        });

        const Mutation = prismaObjectType({
            name: 'Mutation',
            definition(t) {
                t.prismaFields(['*'])
            }
        })

        const schema = makePrismaSchema({
            types: [Query, Mutation],

            prisma: {
                datamodelInfo,
                client: prisma
            },

            outputs: {
                schema: path.join(__dirname, './schema.graphql'),
                typegen: path.join(__dirname, './nexus.ts'),
            },
        });

        return {
            debug: true,
            playground: true,
            schema,
        };
    }
}
🙌 1
I got it to work like this. Using prisma-client and nexus-prisma
Now i will try if i can create computed resolvers
h
Ok
m
I got it to work but I can not create custom `Query`s using
Resolver
and
Query
from nestjs. Do you have an idea?