-
-
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 2 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Task } from "wasp/entities"; | ||
import { GetAllQuery } from "wasp/server/crud/Tasks"; | ||
|
||
export const getAllQuery = ((args, context) => { | ||
return context.entities.Task.findMany({}); | ||
}) satisfies GetAllQuery<{}, Task[]>; |
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
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,82 @@ | ||
module Wasp.Generator.SdkGenerator.CrudG | ||
( genCrud, | ||
) | ||
where | ||
|
||
import Data.Aeson (KeyValue ((.=)), object) | ||
import qualified Data.Aeson.Types as Aeson.Types | ||
import Data.Maybe (fromJust) | ||
import StrongPath (reldir, relfile, (</>)) | ||
import qualified StrongPath as SP | ||
import Wasp.AppSpec (AppSpec, getCruds) | ||
import qualified Wasp.AppSpec as AS | ||
import qualified Wasp.AppSpec.App as AS.App | ||
import qualified Wasp.AppSpec.App.Auth as AS.Auth | ||
import qualified Wasp.AppSpec.Crud as AS.Crud | ||
import Wasp.AppSpec.Valid (getApp, getIdFieldFromCrudEntity, isAuthEnabled) | ||
import Wasp.Generator.Crud (crudDeclarationToOperationsList, getCrudFilePath, getCrudOperationJson, makeCrudOperationKeyAndJsonPair) | ||
import Wasp.Generator.FileDraft (FileDraft) | ||
import qualified Wasp.Generator.JsImport as GJI | ||
import Wasp.Generator.Monad (Generator) | ||
import qualified Wasp.Generator.SdkGenerator.Common as C | ||
import Wasp.Generator.SdkGenerator.ServerOpsGenerator (extImportToJsImport) | ||
import Wasp.Util ((<++>)) | ||
|
||
genCrud :: AppSpec -> Generator [FileDraft] | ||
genCrud spec = | ||
if areThereAnyCruds | ||
then | ||
genCrudOperations spec cruds | ||
<++> genCrudServerOperations spec cruds | ||
else return [] | ||
where | ||
cruds = getCruds spec | ||
areThereAnyCruds = not $ null cruds | ||
|
||
genCrudOperations :: AppSpec -> [(String, AS.Crud.Crud)] -> Generator [FileDraft] | ||
genCrudOperations spec cruds = return $ map genCrudOperation cruds | ||
where | ||
genCrudOperation :: (String, AS.Crud.Crud) -> FileDraft | ||
genCrudOperation (name, crud) = C.mkTmplFdWithDstAndData tmplPath destPath (Just tmplData) | ||
where | ||
tmplPath = [relfile|crud/_crud.ts|] | ||
destPath = [reldir|crud|] </> fromJust (SP.parseRelFile (name ++ ".ts")) | ||
tmplData = getCrudOperationJson name crud idField | ||
idField = getIdFieldFromCrudEntity spec crud | ||
|
||
genCrudServerOperations :: AppSpec -> [(String, AS.Crud.Crud)] -> Generator [FileDraft] | ||
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. Moved from |
||
genCrudServerOperations spec cruds = return $ map genCrudOperation cruds | ||
where | ||
genCrudOperation :: (String, AS.Crud.Crud) -> FileDraft | ||
genCrudOperation (name, crud) = C.mkTmplFdWithDstAndData tmplPath destPath (Just tmplData) | ||
where | ||
tmplPath = [relfile|server/crud/_operations.ts|] | ||
destPath = [reldir|server/crud|] </> getCrudFilePath name "ts" | ||
tmplData = | ||
object | ||
[ "crud" .= getCrudOperationJson name crud idField, | ||
"isAuthEnabled" .= isAuthEnabled spec, | ||
"userEntityUpper" .= maybeUserEntity, | ||
"overrides" .= object overrides, | ||
"queryType" .= queryTsType, | ||
"actionType" .= actionTsType | ||
] | ||
idField = getIdFieldFromCrudEntity spec crud | ||
maybeUserEntity = AS.refName . AS.Auth.userEntity <$> maybeAuth | ||
maybeAuth = AS.App.auth $ snd $ getApp spec | ||
|
||
queryTsType :: String | ||
queryTsType = if isAuthEnabled spec then "AuthenticatedQuery" else "Query" | ||
|
||
actionTsType :: String | ||
actionTsType = if isAuthEnabled spec then "AuthenticatedAction" else "Action" | ||
|
||
overrides :: [Aeson.Types.Pair] | ||
overrides = map operationToOverrideImport crudOperations | ||
|
||
crudOperations = crudDeclarationToOperationsList crud | ||
|
||
operationToOverrideImport :: (AS.Crud.CrudOperation, AS.Crud.CrudOperationOptions) -> Aeson.Types.Pair | ||
operationToOverrideImport (operation, options) = makeCrudOperationKeyAndJsonPair operation importJson | ||
where | ||
importJson = GJI.jsImportToImportJson $ extImportToJsImport <$> AS.Crud.overrideFn options |
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ import Wasp.AppSpec.Operation (getName) | |
import qualified Wasp.AppSpec.Operation as AS.Operation | ||
import qualified Wasp.AppSpec.Query as AS.Query | ||
import Wasp.AppSpec.Valid (isAuthEnabled) | ||
import Wasp.Generator.Common (makeJsonWithEntityData) | ||
import Wasp.Generator.Common (dropExtensionFromImportPath, makeJsonWithEntityData) | ||
import Wasp.Generator.FileDraft (FileDraft) | ||
import qualified Wasp.Generator.JsImport as GJI | ||
import Wasp.Generator.Monad (Generator) | ||
|
@@ -140,21 +140,18 @@ extImportToJsImport extImport@(EI.ExtImport extImportName extImportPath) = | |
_importAlias = Just $ EI.importIdentifier extImport ++ "_ext" | ||
} | ||
where | ||
importPath = C.makeSdkImportPath $ extCodeDirP </> SP.castRel extImportPath | ||
importPath = C.makeSdkImportPath $ extCodeDirP </> importPathWithoutExtension | ||
-- We are dropping extensions here because of the way the "exports" field works in package.json. | ||
-- If we left the extension, it would resolve the import e.g. ext-src/foo.js to ext-src/foo.js.js, | ||
-- which is not what we want. | ||
importPathWithoutExtension = dropExtensionFromImportPath (SP.castRel extImportPath) | ||
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. Please take at look at this piece and the comment. |
||
extCodeDirP = fromJust $ SP.relDirToPosix C.extCodeDirInSdkRootDir | ||
importName = GJI.extImportNameToJsImportName extImportName | ||
|
||
-- extImportToImportJson :: EI.ExtImport -> Aeson.Value | ||
-- extImportToImportJson extImport@(EI.ExtImport importName importPath) = | ||
-- object | ||
-- [ "isDefined" .= True, | ||
-- "importStatement" .= Debug.trace jsImportStmt jsImportStmt, | ||
-- "importIdentifier" .= importAlias | ||
-- ] | ||
-- extImportToImportJson :: | ||
-- Path Posix (Rel importLocation) (Dir ServerSrcDir) -> | ||
-- Maybe EI.ExtImport -> | ||
-- Aeson.Value | ||
-- extImportToImportJson pathFromImportLocationToSrcDir maybeExtImport = GJI.jsImportToImportJson jsImport | ||
-- where | ||
-- jsImportStmt = case importName of | ||
-- EI.ExtImportModule n -> "import " ++ n ++ " from '" ++ importPathStr ++ "'" | ||
-- EI.ExtImportField n -> "import { " ++ n ++ " as " ++ importAlias ++ " } from '" ++ importPathStr ++ "'" | ||
-- importPathStr = C.makeSdkImportPath $ extCodeDirP </> SP.castRel importPath | ||
-- extCodeDirP = fromJust $ SP.relDirToPosix C.extCodeDirInSdkRootDir | ||
-- importAlias = EI.importIdentifier extImport ++ "User" | ||
-- jsImport = extImportToJsImport pathFromImportLocationToSrcDir <$> maybeExtImport |
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.
Moved from
WebAppGenerator