Advertisement
chukwuyem

schema

Dec 12th, 2020
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { makeSchema, queryType, objectType, idArg, mutationType } from "@nexus/schema";
  2. import { nexusSchemaPrisma } from "nexus-plugin-prisma/schema";
  3. import path from "path";
  4.  
  5. const Company = objectType({
  6.   name: "Company",
  7.   definition(t) {
  8.     t.model.id();
  9.     t.model.name();
  10.    
  11.   },
  12. });
  13.  
  14. const User = objectType({
  15.   name: "User",
  16.   definition(t) {
  17.   t.model.id();            
  18.   t.name();      
  19.   t.email();        
  20.   t.emailVerified();
  21.   t.image();        
  22.   t.createdAt();    
  23.   t.updatedAt();    
  24.    
  25.   },
  26. });
  27.  
  28.  
  29. const Query = queryType({
  30.   definition(t){
  31.     t.crud.company({resolve: (_root, args, ctx) => {
  32.       console.log(ctx)
  33.       return ctx.prisma.company.findOne({where: {id: args.where.id}});
  34.     }});
  35.     t.crud.companies({pagination: true, filtering: true})
  36.    
  37.     // t.nonNull.field("Company", {
  38.     //   type: Company,
  39.     //   args: {
  40.     //     id: idArg()
  41.     //   },
  42.     //   resolve: (_root, {id}, ctx) => {
  43.     //     return ctx.prisma.company.findOne({where: {id:Number(id)}})
  44.     //   }
  45.     // })
  46.   },
  47. })
  48.  
  49. const Mutation = mutationType({
  50.   definition(t){
  51.     t.crud.createOneCompany();
  52.    
  53.     // t.nonNull.field("CreateCompany", {
  54.     //   type: Company,
  55.     //   args: {
  56.     //     id: idArg(),
  57.     //     name: name
  58.     //   },
  59.     //   resolve: (_root, {name}, ctx) => {
  60.     //     return ctx.prisma.company.create({data:{
  61.     //       name: name
  62.     //     }})
  63.     //   }
  64.     // })
  65.   },
  66. })
  67.  
  68.  
  69.  
  70. export const schema = makeSchema({
  71.   types: { Query, Company, Mutation },
  72.   plugins: [nexusSchemaPrisma({experimentalCRUD: true})],
  73.   outputs: {
  74.     schema: path.join(process.cwd(), "schema.graphql"),
  75.     typegen: path.join(process.cwd(), "nexus.ts"),
  76.   },
  77.   typegenAutoConfig: {
  78.     contextType: "Context.Context",
  79.     sources: [
  80.       {
  81.         source: "@prisma/client",
  82.         alias: "prisma",
  83.       },
  84.       {
  85.         source: require.resolve("./context.ts"),
  86.         alias: "Context",
  87.       }
  88.     ]
  89.   }
  90. });
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement