Skip to content

[Bug?]: Maybe Regression: cannot delete /api directory and have the app still build #10264

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

Closed
1 task
cannikin opened this issue Mar 18, 2024 · 6 comments
Closed
1 task
Labels
bug/needs-info More information is needed for reproduction

Comments

@cannikin
Copy link
Member

cannikin commented Mar 18, 2024

What's not working?

Coming soon with RSC, we will no longer have an /api directory. I tried to see how close I could get to this future with the latest canary by deleting everything in /api. The build would fail unless two conditions were met:

  • Thedb/prisma.schema file must be present
  • There must be at least 1 directive in api/src/directives

How do we reproduce the bug?

In the latest canary, delete the /api directory and try to yarn rw build

What's your environment? (If it applies)

No response

Are you interested in working on this?

  • I'm interested in working on this
@Josh-Walker-GM
Copy link
Contributor

I created the test project and then destroyed the API side. I worked through the errors I had getting yarn rw build to work and PR'd the changes in the draft mentioned above.

I didn't run into any directive related issues however so maybe I'm missing something. I'm not sure if we will want the PR but it's there as a starting point I guess. Fancy checking if using that branch works for building your api-less project?

@cannikin
Copy link
Member Author

Thanks for taking this one! Here's what I see if I delete api/src/directives in an app on 8.0.0-canary.295. This is the RSC app I'm using for my walkthrough, so you can check it out and try the same thing: https://github.com/cannikin/cambium-rsc Maybe it only happens if you have experimental RSC/SSR setup?

% yarn rw build
✔ Generating Prisma Client...
✖
  Unable to find any GraphQL type definitions for the following pointers:
  - graphql/**/*.sdl.{js,ts}
  ,
  - directives/**/*.{js,ts}
  ,
  - subscriptions/**/*.{js,ts}
◼ Building API...
◼ Building Web...
-------------------------------------------------------------------------------------------------------------------------------
Error: 
      Unable to find any GraphQL type definitions for the following pointers:
        
          - graphql/**/*.sdl.{js,ts}
          ,
          - directives/**/*.{js,ts}
          ,
          - subscriptions/**/*.{js,ts}
          
    at prepareResult (/Users/rob/Sites/rsc/cambium-rsc/node_modules/@graphql-tools/load/cjs/load-typedefs.js:93:15)
    at loadTypedefs (/Users/rob/Sites/rsc/cambium-rsc/node_modules/@graphql-tools/load/cjs/load-typedefs.js:43:20)
    at async _Task.loadAndValidateSdls [as taskFn] (/Users/rob/Sites/rsc/cambium-rsc/node_modules/@redwoodjs/internal/dist/validateSchema.js:137:26)
    at async _Task.run (/Users/rob/Sites/rsc/cambium-rsc/node_modules/listr2/dist/index.cjs:2049:11)

@Josh-Walker-GM
Copy link
Contributor

Cool thanks! I'll check it out, reproduce it, and update the branch accordingly

@Josh-Walker-GM
Copy link
Contributor

Your goal here was to simply not have a api directory at all right?

My branch will handle that case for your app - the yarn rw build will build the web successfully. I didn't code it to handle the case of only having some api side files like you have in the latest commit to that repo.

What are your thoughts on build working for either:

  1. You have no api directory whatsoever
  2. You have an api directory but it has some requirements, like a directive, schema etc

I don't know if it'll be wise to try go through any possible partial state the api side might be in right? 😅

@cannikin
Copy link
Member Author

Yep I wanted to be able to remove /api completely, but if I removed /db or /directives then the build wouldn't complete, so that's as close as I could get (so that people could still clone the repo and follow along with the Walkthrough). But you're saying that with your branch I could now remove those and everything builds? That's great! Let's get this merged and a new canary pushed ASAP!

Those two cases sounds good to me, I definitely wasn't thinking we should try to get api to build in all possible permutations of files/directories that could be present. I would say the only cases to worry about are /api doesn't exist at all, or /api contains everything we would expect a regular Redwood app to have.

Josh-Walker-GM added a commit that referenced this issue Mar 21, 2024
#10265)

**Problem**
This PR address the issue raised in #10264 which highlighted that `yarn
rw build` would fail for projects that have removed the `api` directory.

**Changes**
1. The `yarn rw build` command now checks for the existence of the
prisma schema file. It will not generate the prisma client if the file
does not exist and it will not trigger prerendering if the schema file
does not exist.
2. Updates the checks performed by `yarn rw serve` to handle the case
when there is not API side a little nicer. It will offer more specific
error messages when you run `yarn rw serve api` without an API side and
it will tell you to run `yarn rw serve web` instead of `yarn rw serve`
if you have no API side.

**Concerns**
1. I'm not sure about adding checks for "does the API side even exist"
anywhere we previously assumed it did. For now these checks only needed
to happen in 2 places so I'm not that bothered about them but I can see
how it could spiral out of control.
@Josh-Walker-GM
Copy link
Contributor

Fixed in #10265 and improved in #10275

thedavidprice pushed a commit that referenced this issue Mar 27, 2024
#10265)

**Problem**
This PR address the issue raised in #10264 which highlighted that `yarn
rw build` would fail for projects that have removed the `api` directory.

**Changes**
1. The `yarn rw build` command now checks for the existence of the
prisma schema file. It will not generate the prisma client if the file
does not exist and it will not trigger prerendering if the schema file
does not exist.
2. Updates the checks performed by `yarn rw serve` to handle the case
when there is not API side a little nicer. It will offer more specific
error messages when you run `yarn rw serve api` without an API side and
it will tell you to run `yarn rw serve web` instead of `yarn rw serve`
if you have no API side.

**Concerns**
1. I'm not sure about adding checks for "does the API side even exist"
anywhere we previously assumed it did. For now these checks only needed
to happen in 2 places so I'm not that bothered about them but I can see
how it could spiral out of control.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction
Projects
None yet
Development

No branches or pull requests

2 participants