(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[774],{4515:function(s,e,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/docs/plugins/prisma-utils",function(){return a(8013)}])},8013:function(s,e,a){"use strict";a.r(e),a.d(e,{__N_SSG:function(){return r},frontmatter:function(){return i}});var l=a(5250),n=a(7160),t=a(3210),r=!0;let i={name:"Prisma plugin-utils",title:"Prisma utils for creating input types",menu:"Plugins",description:"Prisma utils for creating input types"},c=t.k;function h(s){let e=Object.assign({h1:"h1",p:"p",h2:"h2",pre:"pre",code:"code",span:"span",h3:"h3",h4:"h4",ol:"ol",li:"li",a:"a"},(0,n.ah)(),s.components);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(e.h1,{id:"prisma-utils-for-pothos",children:"Prisma utils for Pothos"}),"\n",(0,l.jsx)(e.p,{children:"This package is highly experimental and not recommended for production use"}),"\n",(0,l.jsx)(e.p,{children:"The plugin adds new helpers for creating prisma compatible input types. It is NOT required to use\nthe normal prisma plugin."}),"\n",(0,l.jsx)(e.h2,{id:"setup",children:"Setup"}),"\n",(0,l.jsx)(e.p,{children:"To use this plugin, you will need to enable prismaUtils option in the generator in your\nschema.prisma:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsx)(e.code,{children:'generator pothos {\n  provider     = "prisma-pothos-types"\n  // Enable prismaUtils feature\n  prismaUtils  = true\n}\n'})}),"\n",(0,l.jsx)(e.p,{children:"Once this is enabled, you can add the plugin to your schema along with the normal prisma plugin:"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-ts",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaClient"})," } ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@prisma/client'"}),";\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"type"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaTypes"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-prisma/generated'"}),";\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaPlugin"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-prisma'"}),";\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaUtils"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@pothos/plugin-prisma-utils'"}),";\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," prisma = ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaClient"}),"({});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"default"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"new"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"SchemaBuilder"}),"<{\n  ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Scalars"}),": {\n    ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"DateTime"}),": {\n      ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Input"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Date"}),";\n      ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Output"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Date"}),";\n    };\n  };\n  ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaTypes"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaTypes"}),";\n}>({\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"plugins"}),": [",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaPlugin"}),", ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PrismaUtils"}),"],\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"prisma"}),": {\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"client"}),": prisma,\n  },\n});\n"]})}),"\n",(0,l.jsx)(e.h2,{id:"what-can-you-do-with-this-plugin",children:"What can you do with this plugin"}),"\n",(0,l.jsx)(e.p,{children:"Currently this plugin is focused on making it easier to define prisma compatible input types that\ntake advantage of the types defined in your Prisma schema."}),"\n",(0,l.jsx)(e.p,{children:"The goal is not to generate all input types automatically, but rather to provide building blocks so\nthat writing your own helpers or code-generators becomes a lot easier. There are far too many\ntradeoffs and choices to be made when designing input types for queries that one solution won't work\nfor everyone."}),"\n",(0,l.jsx)(e.p,{children:"This plugin will eventually provide more helpers and examples that should allow anyone to quickly\nset something up to automatically creates all their input types (and eventually other crud\noperations)."}),"\n",(0,l.jsx)(e.h2,{id:"what-is-supported-so-far",children:"What is supported so far"}),"\n",(0,l.jsx)(e.h3,{id:"creating-filter-types-for-scalars-and-enums",children:"Creating filter types for scalars and enums"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"StringFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaFilter"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'contains'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'equals'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'startsWith'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'not'"}),"],\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IDFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaFilter"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Int'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'equals'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'not'"}),"],\n});\n\nbuilder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"enumType"}),"(",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"MyEnum"}),", { ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'MyEnum'"})," });\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"MyEnumFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaFilter"}),"(",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"MyEnum"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'not'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'equals'"}),"],\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"creating-filters-for-prisma-objects-compatible-with-a-where-clause",children:'Creating filters for Prisma objects (compatible with a "where" clause)'}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserWhere"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaWhere"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": {\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"id"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IDFilter"}),",\n  },\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaWhere"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Post'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsxs)(e.span,{className:"hljs-function",children:["(",(0,l.jsx)(e.span,{className:"hljs-params",children:"t"}),") =>"]})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// You can use either filters"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"id"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IDFilter"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// or scalar types to only support equality"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"title"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"createdAt"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'DateTime'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// Relations are supported by referencing other scalars"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"author"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserFilter"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// use t.field to provide other field options"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"authorId"}),": t.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"field"}),"({ ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"type"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IDFilter"}),", ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"description"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'filter by author id'"})," }),\n  }),\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"creating-list-filters-for-scalars",children:"Creating list filters for scalars"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"StringListFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaScalarListFilter"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'StringListFilter'"}),",\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'has'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'hasSome'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'hasEvery'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'isEmpty'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'equals'"}),"],\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"creating-list-filters-for-prisma-objects",children:"Creating list filters for Prisma objects"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserListFilter"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaListFilter"}),"(",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserWhere"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'every'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'some'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'none'"}),"],\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"creating-orderby-input-types",children:"Creating OrderBy input types"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-typescript",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserOrderBy"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaOrderBy"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": {\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n  },\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostOrderBy"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaOrderBy"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Post'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"id"}),": ",(0,l.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"title"}),": ",(0,l.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"createdAt"}),": ",(0,l.jsx)(e.span,{className:"hljs-literal",children:"true"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"author"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserOrderBy"}),",\n  }),\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"inputs-for-create-mutations",children:"Inputs for create mutations"}),"\n",(0,l.jsxs)(e.p,{children:["You can use ",(0,l.jsx)(e.code,{children:"builder.prismaCreate"})," to create input types for create mutations."]}),"\n",(0,l.jsx)(e.p,{children:"To get these types to work correctly for circular references, it is recommended to add explicit type\nannotations, but for simple types that do not have circular references the explicit types can be\nomitted."}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-ts",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"InputObjectRef"})," } ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@pothos/core'"}),";\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"import"})," { ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Prisma"})," } ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"from"})," ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'@prisma/client'"}),";\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserCreate"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"InputObjectRef"}),"<",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Prisma"}),".",(0,l.jsx)(e.span,{className:"hljs-property",children:"UserCreateInput"}),"> = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaCreate"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'UserCreate'"}),",\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// scalars"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"id"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Int'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"email"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// inputs for relations need to be defined separately as shown below"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"profile"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserCreateProfile"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// create fields for list relations are defined just like normal relations."}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// Pothos will automatically handle making the inputs lists"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"posts"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserCreatePosts"}),",\n  }),\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserCreateProfile"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaCreateRelation"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'profile'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaCreate as shown above for User"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"create"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"ProfileCreateWithoutUser"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhere"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"connect"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"ProfileUniqueFilter"}),",\n  }),\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserCreatePosts"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaCreateRelation"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'posts'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaCreate as shown above for User"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"create"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostCreateWithoutAuthor"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhere"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"connect"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n  }),\n});\n"]})}),"\n",(0,l.jsx)(e.h3,{id:"inputs-for-update-mutations",children:"Inputs for update mutations"}),"\n",(0,l.jsxs)(e.p,{children:["You can use ",(0,l.jsx)(e.code,{children:"builder.prismaUpdate"})," to Update input types for update mutations."]}),"\n",(0,l.jsx)(e.p,{children:"To get these types to work correctly for circular references, it is recommended to add explicit type\nannotations, but for simple types that do not have circular references the explicit types can be\nomitted."}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-ts",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserUpdate"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"InputObjectRef"}),"<",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"Prisma"}),".",(0,l.jsx)(e.span,{className:"hljs-property",children:"Prisma"}),".",(0,l.jsx)(e.span,{className:"hljs-property",children:"UserUpdateInput"}),"> = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaUpdate"}),"(\n  ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),",\n  {\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'UserUpdate'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"id"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Int'"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"email"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// inputs for relations need to be defined separately as shown below"}),"\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"profile"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserUpdateProfile"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"posts"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserUpdatePosts"}),",\n    }),\n  },\n);\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserUpdateProfile"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaUpdateRelation"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'profile'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaCreate"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"create"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"ProfileCreateWithoutUser"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaUpdate"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"update"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"ProfileUpdateWithoutUser"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhereUnique"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"connect"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"ProfileUniqueFilter"}),",\n  }),\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"UserUpdatePosts"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaUpdateRelation"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'User'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'posts'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// Not all update methods need to be defined"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaCreate"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"create"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostCreateWithoutAuthor"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhereUnique"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"set"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhereUnique"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"disconnect"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"delete"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"connect"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"update"}),": {\n      ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhereUnique"}),"\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"where"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUniqueFilter"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaUpdate"}),"\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"data"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUpdateWithoutAuthor"}),",\n    },\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"updateMany"}),": {\n      ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhere"}),"\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"where"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostWithoutAuthorFilter"}),",\n      ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaUpdate"}),"\n      ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"data"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUpdateWithoutAuthor"}),",\n    },\n    ",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// created with builder.prismaWhere"}),"\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"deleteMany"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostWithoutAuthorFilter"}),",\n  }),\n});\n"]})}),"\n",(0,l.jsx)(e.h4,{id:"atomic-int-update-operations",children:"Atomic Int Update operations"}),"\n",(0,l.jsx)(e.pre,{children:(0,l.jsxs)(e.code,{className:"hljs language-ts",children:[(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IntUpdate"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaIntAtomicUpdate"}),"();\n",(0,l.jsx)(e.span,{className:"hljs-comment",children:"// or with options"}),"\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IntUpdate"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaIntAtomicUpdate"}),"({\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'IntUpdate'"}),",\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"ops"}),": [",(0,l.jsx)(e.span,{className:"hljs-string",children:"'increment'"}),", ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'decrement'"}),"],\n});\n\n",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"export"})," ",(0,l.jsx)(e.span,{className:"hljs-keyword",children:"const"})," ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"PostUpdate"})," = builder.",(0,l.jsx)(e.span,{className:"hljs-title function_",children:"prismaUpdate"}),"(",(0,l.jsx)(e.span,{className:"hljs-string",children:"'Post'"}),", {\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"name"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'PostUpdate'"}),",\n  ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"fields"}),": ",(0,l.jsx)(e.span,{className:"hljs-function",children:"() =>"})," ({\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"title"}),": ",(0,l.jsx)(e.span,{className:"hljs-string",children:"'String'"}),",\n    ",(0,l.jsx)(e.span,{className:"hljs-attr",children:"views"}),": ",(0,l.jsx)(e.span,{className:"hljs-title class_",children:"IntUpdate"}),",\n  }),\n});\n"]})}),"\n",(0,l.jsx)(e.h2,{id:"generators",children:"Generators"}),"\n",(0,l.jsx)(e.p,{children:"Manually defining all the different input types shown above for a large number of tables can become\nvery repetitive. These utilities are designed to be building blocks for generators or utility\nfunctions, so that you don't need to hand write these types yourself."}),"\n",(0,l.jsx)(e.p,{children:"Pothos does not currently ship an official generator for prisma types, but there are a couple of\nexample generators that can be copied and modified to suite your needs. These are intentionally\nsomewhat limited in functionality and not written to be easily exported because they will be updated\nwith breaking changes as these utilities are developed further. They are only intended as building\nblocks for you to build you own generators."}),"\n",(0,l.jsx)(e.p,{children:"There are 2 main approaches:"}),"\n",(0,l.jsxs)(e.ol,{children:["\n",(0,l.jsx)(e.li,{children:"Static Generation: Types are generated and written as a typescript file which can be imported\nfrom as part of your schema"}),"\n",(0,l.jsx)(e.li,{children:"Dynamic Generation: Types are generated dynamically at runtime through helpers imported from your\nApp"}),"\n"]}),"\n",(0,l.jsx)(e.h3,{id:"static-generator",children:"Static generator"}),"\n",(0,l.jsxs)(e.p,{children:["You can find an\n",(0,l.jsx)(e.a,{href:"https://github.com/hayes/pothos/blob/main/packages/plugin-prisma-utils/tests/examples/codegen/generator.ts",children:"example static generator here"})]}),"\n",(0,l.jsxs)(e.p,{children:["This generator will generate a file with input types for every table in your schema as shown\n",(0,l.jsx)(e.a,{href:"https://github.com/hayes/pothos/blob/main/packages/plugin-prisma-utils/tests/examples/codegen/schema/prisma-inputs.ts",children:"here"})]}),"\n",(0,l.jsxs)(e.p,{children:["These generated types can be used in your schema as shown\n",(0,l.jsx)(e.a,{href:"https://github.com/hayes/pothos/blob/main/packages/plugin-prisma-utils/tests/examples/codegen/schema/index.ts",children:"here"})]}),"\n",(0,l.jsx)(e.h3,{id:"dynamic-generator",children:"Dynamic generator"}),"\n",(0,l.jsxs)(e.p,{children:["You can find an example\n",(0,l.jsx)(e.a,{href:"https://github.com/hayes/pothos/blob/main/packages/plugin-prisma-utils/tests/examples/crud/generator.ts",children:"dynamic generator here"})]}),"\n",(0,l.jsxs)(e.p,{children:["This generator exports a class that can be used to dynamically create input types for your builder\nas shown\n",(0,l.jsx)(e.a,{href:"https://github.com/hayes/pothos/blob/main/packages/plugin-prisma-utils/tests/examples/crud/schema/index.ts#L9-L20",children:"here"})]})]})}e.default=function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,l.jsx)(c,Object.assign({},s,{children:(0,l.jsx)(h,s)}))}}},function(s){s.O(0,[8430,3210,9774,2888,179],function(){return s(s.s=4515)}),_N_E=s.O()}]);