Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { makeSchema, queryType, objectType, idArg, mutationType } from "@nexus/schema";
- import { nexusSchemaPrisma } from "nexus-plugin-prisma/schema";
- import path from "path";
- const Company = objectType({
- name: "Company",
- definition(t) {
- t.model.id();
- t.model.name();
- },
- });
- const User = objectType({
- name: "User",
- definition(t) {
- t.model.id();
- t.name();
- t.email();
- t.emailVerified();
- t.image();
- t.createdAt();
- t.updatedAt();
- },
- });
- const Query = queryType({
- definition(t){
- t.crud.company({resolve: (_root, args, ctx) => {
- console.log(ctx)
- return ctx.prisma.company.findOne({where: {id: args.where.id}});
- }});
- t.crud.companies({pagination: true, filtering: true})
- // t.nonNull.field("Company", {
- // type: Company,
- // args: {
- // id: idArg()
- // },
- // resolve: (_root, {id}, ctx) => {
- // return ctx.prisma.company.findOne({where: {id:Number(id)}})
- // }
- // })
- },
- })
- const Mutation = mutationType({
- definition(t){
- t.crud.createOneCompany();
- // t.nonNull.field("CreateCompany", {
- // type: Company,
- // args: {
- // id: idArg(),
- // name: name
- // },
- // resolve: (_root, {name}, ctx) => {
- // return ctx.prisma.company.create({data:{
- // name: name
- // }})
- // }
- // })
- },
- })
- export const schema = makeSchema({
- types: { Query, Company, Mutation },
- plugins: [nexusSchemaPrisma({experimentalCRUD: true})],
- outputs: {
- schema: path.join(process.cwd(), "schema.graphql"),
- typegen: path.join(process.cwd(), "nexus.ts"),
- },
- typegenAutoConfig: {
- contextType: "Context.Context",
- sources: [
- {
- source: "@prisma/client",
- alias: "prisma",
- },
- {
- source: require.resolve("./context.ts"),
- alias: "Context",
- }
- ]
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement