-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes CRUD feature to work with SDK #1656
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6462a35
Fixes CRUD feature to work with SDK
infomiho fd44a90
Merge branch 'filip-sdk' into miho-crud-fixes
infomiho ea90c3e
Cleanup
infomiho d1e1cd1
Merge branch 'filip-sdk' into miho-crud-fixes
infomiho 95da167
Clenaup
infomiho 07f85af
Merge branch 'filip-sdk' into miho-crud-fixes
infomiho e111e31
Merge branch 'filip-sdk' into miho-crud-fixes
infomiho a84f2f3
Merge branch 'filip-sdk' into miho-crud-fixes
infomiho 6127ee6
Server uses direct imports for crud overrides
infomiho 8ab4708
Merge branch 'filip-sdk' into miho-crud-fixes
sodic cf0c074
Refactor SDK crud generator
sodic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
waspc/data/Generator/templates/sdk/server/crud/_operationTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{{={= =}=}} | ||
import type { | ||
{=# isAuthEnabled =} | ||
AuthenticatedAction, | ||
AuthenticatedQuery, | ||
{=/ isAuthEnabled =} | ||
{=^ isAuthEnabled =} | ||
Action, | ||
Query, | ||
{=/ isAuthEnabled =} | ||
_{= crud.entityUpper =}, | ||
} from "wasp/server/_types"; | ||
import type { Prisma } from "@prisma/client"; | ||
import { Payload } from "wasp/server/_types/serialization"; | ||
import type { | ||
{= crud.entityUpper =}, | ||
} from "wasp/entities"; | ||
{=# overrides.GetAll.isDefined =} | ||
{=& overrides.GetAll.importStatement =} | ||
{=/ overrides.GetAll.isDefined =} | ||
{=# overrides.Get.isDefined =} | ||
{=& overrides.Get.importStatement =} | ||
{=/ overrides.Get.isDefined =} | ||
{=# overrides.Create.isDefined =} | ||
{=& overrides.Create.importStatement =} | ||
{=/ overrides.Create.isDefined =} | ||
{=# overrides.Update.isDefined =} | ||
{=& overrides.Update.importStatement =} | ||
{=/ overrides.Update.isDefined =} | ||
{=# overrides.Delete.isDefined =} | ||
{=& overrides.Delete.importStatement =} | ||
{=/ overrides.Delete.isDefined =} | ||
|
||
type _WaspEntityTagged = _{= crud.entityUpper =} | ||
type _WaspEntity = {= crud.entityUpper =} | ||
|
||
{=# crud.operations.GetAll =} | ||
// Get All query | ||
export type GetAllQuery<Input extends Payload, Output extends Payload> = {= queryType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.GetAll.isDefined =} | ||
type GetAllInput = {} | ||
type GetAllOutput = _WaspEntity[] | ||
export type GetAllQueryResolved = GetAllQuery<GetAllInput, GetAllOutput> | ||
{=/ overrides.GetAll.isDefined =} | ||
{=# overrides.GetAll.isDefined =} | ||
const _waspGetAllQuery = {= overrides.GetAll.importIdentifier =} | ||
export type GetAllQueryResolved = typeof _waspGetAllQuery | ||
{=/ overrides.GetAll.isDefined =} | ||
{=/ crud.operations.GetAll =} | ||
|
||
{=# crud.operations.Get =} | ||
// Get query | ||
export type GetQuery<Input extends Payload, Output extends Payload> = {= queryType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Get.isDefined =} | ||
type GetInput = Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type GetOutput = _WaspEntity | null | ||
export type GetQueryResolved = GetQuery<GetInput, GetOutput> | ||
{=/ overrides.Get.isDefined =} | ||
{=# overrides.Get.isDefined =} | ||
const _waspGetQuery = {= overrides.Get.importIdentifier =} | ||
export type GetQueryResolved = typeof _waspGetQuery | ||
{=/ overrides.Get.isDefined =} | ||
{=/ crud.operations.Get =} | ||
|
||
{=# crud.operations.Create =} | ||
// Create action | ||
export type CreateAction<Input extends Payload, Output extends Payload>= {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Create.isDefined =} | ||
type CreateInput = Prisma.{= crud.entityUpper =}CreateInput | ||
type CreateOutput = _WaspEntity | ||
export type CreateActionResolved = CreateAction<CreateInput, CreateOutput> | ||
{=/ overrides.Create.isDefined =} | ||
{=# overrides.Create.isDefined =} | ||
const _waspCreateAction = {= overrides.Create.importIdentifier =} | ||
export type CreateActionResolved = typeof _waspCreateAction | ||
{=/ overrides.Create.isDefined =} | ||
{=/ crud.operations.Create =} | ||
|
||
{=# crud.operations.Update =} | ||
// Update action | ||
export type UpdateAction<Input extends Payload, Output extends Payload> = {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Update.isDefined =} | ||
type UpdateInput = Prisma.{= crud.entityUpper =}UpdateInput & Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type UpdateOutput = _WaspEntity | ||
export type UpdateActionResolved = UpdateAction<UpdateInput, UpdateOutput> | ||
{=/ overrides.Update.isDefined =} | ||
{=# overrides.Update.isDefined =} | ||
const _waspUpdateAction = {= overrides.Update.importIdentifier =} | ||
export type UpdateActionResolved = typeof _waspUpdateAction | ||
{=/ overrides.Update.isDefined =} | ||
{=/ crud.operations.Update =} | ||
|
||
{=# crud.operations.Delete =} | ||
// Delete action | ||
export type DeleteAction<Input extends Payload, Output extends Payload> = {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Delete.isDefined =} | ||
type DeleteInput = Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type DeleteOutput = _WaspEntity | ||
export type DeleteActionResolved = DeleteAction<DeleteInput, DeleteOutput> | ||
{=/ overrides.Delete.isDefined =} | ||
{=# overrides.Delete.isDefined =} | ||
const _waspDeleteAction = {= overrides.Delete.importIdentifier =} | ||
export type DeleteActionResolved = typeof _waspDeleteAction | ||
{=/ overrides.Delete.isDefined =} | ||
{=/ crud.operations.Delete =} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,14 @@ | ||
{{={= =}=}} | ||
import prisma from "wasp/server/dbClient"; | ||
|
||
import type { | ||
{=# isAuthEnabled =} | ||
AuthenticatedAction, | ||
AuthenticatedQuery, | ||
{=/ isAuthEnabled =} | ||
{=^ isAuthEnabled =} | ||
Action, | ||
Query, | ||
{=/ isAuthEnabled =} | ||
_{= crud.entityUpper =}, | ||
} from "../_types"; | ||
import type { Prisma } from "@prisma/client"; | ||
import { Payload } from "../_types/serialization.js"; | ||
import type { | ||
{= crud.entityUpper =}, | ||
} from "../entities"; | ||
} from "wasp/entities"; | ||
{=# isAuthEnabled =} | ||
import { throwInvalidCredentialsError } from '../auth/utils.js' | ||
import { throwInvalidCredentialsError } from 'wasp/auth/utils' | ||
{=/ isAuthEnabled =} | ||
import type { GetAllQuery, GetQuery, CreateAction, UpdateAction, DeleteAction } from "{= crudTypesImportPath =}"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are importing the CRUD types from the SDK |
||
{=# overrides.GetAll.isDefined =} | ||
{=& overrides.GetAll.importStatement =} | ||
{=/ overrides.GetAll.isDefined =} | ||
|
@@ -36,7 +25,6 @@ import { throwInvalidCredentialsError } from '../auth/utils.js' | |
{=& overrides.Delete.importStatement =} | ||
{=/ overrides.Delete.isDefined =} | ||
|
||
type _WaspEntityTagged = _{= crud.entityUpper =} | ||
type _WaspEntity = {= crud.entityUpper =} | ||
const entities = { | ||
{= crud.entityUpper =}: prisma.{= crud.entityLower =}, | ||
|
@@ -48,12 +36,7 @@ const entities = { | |
{=# crud.operations.GetAll =} | ||
// Get All query | ||
{=! | ||
// 1. We define the type for the operation using "queryType" template variable which is either | ||
// AuthenticatedQuery or Query (it depends on whether auth is enabled or not). | ||
=} | ||
export type GetAllQuery<Input extends Payload, Output extends Payload> = {= queryType =}<[_WaspEntityTagged], Input, Output> | ||
{=! | ||
// 2. Then, we either use the default implementation of the operation... | ||
// 1. We either use the default implementation of the operation... | ||
=} | ||
{=^ overrides.GetAll.isDefined =} | ||
type GetAllInput = {} | ||
|
@@ -74,13 +57,7 @@ const _waspGetAllQuery = {= overrides.GetAll.importIdentifier =} | |
{=/ overrides.GetAll.isDefined =} | ||
|
||
{=! | ||
// 3. We then define the final type for the operation, which is the type of the function we defined in the previous step. | ||
// It will pick up either the default implementation or the one from the overrides. | ||
=} | ||
export type GetAllQueryResolved = typeof _waspGetAllQuery | ||
|
||
{=! | ||
// 4. We define a function that is used as the Express route handler | ||
// 2. We define a function that is used as the Express route handler | ||
=} | ||
export async function getAllFn(args, context) { | ||
return (_waspGetAllQuery as any)(args, { | ||
|
@@ -95,7 +72,6 @@ export async function getAllFn(args, context) { | |
|
||
{=# crud.operations.Get =} | ||
// Get query | ||
export type GetQuery<Input extends Payload, Output extends Payload> = {= queryType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Get.isDefined =} | ||
type GetInput = Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type GetOutput = _WaspEntity | null | ||
|
@@ -109,7 +85,6 @@ const _waspGetQuery: GetQuery<GetInput, GetOutput> = ((args, context) => { | |
{=# overrides.Get.isDefined =} | ||
const _waspGetQuery = {= overrides.Get.importIdentifier =} | ||
{=/ overrides.Get.isDefined =} | ||
export type GetQueryResolved = typeof _waspGetQuery | ||
|
||
export async function getFn(args, context) { | ||
return (_waspGetQuery as any)(args, { | ||
|
@@ -121,7 +96,6 @@ export async function getFn(args, context) { | |
|
||
{=# crud.operations.Create =} | ||
// Create action | ||
export type CreateAction<Input extends Payload, Output extends Payload>= {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Create.isDefined =} | ||
type CreateInput = Prisma.{= crud.entityUpper =}CreateInput | ||
type CreateOutput = _WaspEntity | ||
|
@@ -136,8 +110,6 @@ const _waspCreateAction: CreateAction<CreateInput, CreateOutput> = ((args, conte | |
const _waspCreateAction = {= overrides.Create.importIdentifier =} | ||
{=/ overrides.Create.isDefined =} | ||
|
||
export type CreateActionResolved = typeof _waspCreateAction | ||
|
||
export async function createFn(args, context) { | ||
return (_waspCreateAction as any)(args, { | ||
...context, | ||
|
@@ -148,7 +120,6 @@ export async function createFn(args, context) { | |
|
||
{=# crud.operations.Update =} | ||
// Update action | ||
export type UpdateAction<Input extends Payload, Output extends Payload> = {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Update.isDefined =} | ||
type UpdateInput = Prisma.{= crud.entityUpper =}UpdateInput & Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type UpdateOutput = _WaspEntity | ||
|
@@ -167,8 +138,6 @@ const _waspUpdateAction: UpdateAction<UpdateInput, UpdateOutput> = ((args, conte | |
const _waspUpdateAction = {= overrides.Update.importIdentifier =} | ||
{=/ overrides.Update.isDefined =} | ||
|
||
export type UpdateActionResolved = typeof _waspUpdateAction | ||
|
||
export async function updateFn(args, context) { | ||
return (_waspUpdateAction as any)(args, { | ||
...context, | ||
|
@@ -179,7 +148,6 @@ export async function updateFn(args, context) { | |
|
||
{=# crud.operations.Delete =} | ||
// Delete action | ||
export type DeleteAction<Input extends Payload, Output extends Payload> = {= actionType =}<[_WaspEntityTagged], Input, Output> | ||
{=^ overrides.Delete.isDefined =} | ||
type DeleteInput = Prisma.{= crud.entityUpper =}WhereUniqueInput | ||
type DeleteOutput = _WaspEntity | ||
|
@@ -195,8 +163,6 @@ const _waspDeleteAction: DeleteAction<DeleteInput, DeleteOutput> = ((args, conte | |
const _waspDeleteAction = {= overrides.Delete.importIdentifier =} | ||
{=/ overrides.Delete.isDefined =} | ||
|
||
export type DeleteActionResolved = typeof _waspDeleteAction | ||
|
||
export async function deleteFn(args, context) { | ||
return (_waspDeleteAction as any)(args, { | ||
...context, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generate server crud types in the SDK so they can be used for full-stack type safety.