HoudiniGraphql / houdini

The disappearing GraphQL client

Home Page:http://www.houdinigraphql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schema is not updated on `schemaPath` file changes when schema file is outside of project's directory

V-ed opened this issue · comments

Describe the bug

Houdini's config file houdini.config.js allows to use a schemaPath file to use as its schema source, but this file is not watched.

image

This issue makes it a bit annoying to work in a monorepo, as every change to the API I make needs to be reflected in houdini via a client restart (and I mean a full stop and start, as simply restarting the vite server with r is not enough). While vite is fast to start, this messes up my workflow of using vscode tasks to debug my websites, and I must close everything and reopen everything, losing context.

Severity

annoyance

Steps to Reproduce the Bug

  1. Setup bare repo with a random graphql schema file
  2. Use schemaPath in houdini.config.js to point to this graphql schema file
  3. Start Vite server
  4. Update graphql schema file with new query
  5. Try to use new query in repo

Reproduction

No response

commented

Yes, if I remember correctly, vite can't watch outside of its directory.

I could see 3 workarounds:
A/ At the root level of the monorepo, add vite-plugin-watch-and-run and trigger cd myPath && npm run houdini generate on this file change?

B/ The API could write into 2 places at the same time?

C/ You could watch the schema via watchSchema option in http mode

What do you think?

Yes, if I remember correctly, vite can't watch outside of its directory.

I could see 3 workarounds: A/ At the root level of the monorepo, add vite-plugin-watch-and-run and trigger cd myPath && npm run houdini generate on this file change?

B/ The API could write into 2 places at the same time?

C/ You could watch the schema via watchSchema option in http mode

What do you think?

Ah, I see how this isn't feasible to watch as a vite plugin then, I'll see about some of these features!

For the C/ option, I do not believe it works with both using schemaPath and watchSchema.url ; Updating the schema (both the file and the endpoint at the same time) does not update houdini.

For the A/ option, is using houdini generate updating houdini's vite plugin watcher? or would I need to disable houdini's vite plugin watcher while running a custom watcher + manual generate command?

commented

Yeah, sorry I didn't elaborate too much.

For C/, I was thinking to remove the schemaPath and it would create a local ./schema.graphql that will be used for the frontend portion.

For A/, same thing, removing schemaPath, so that generate regenerate the schema file for the frontend when needed. You still need to keep the vite houdini plugin as it's doing a lot more things ;)

No worries, I like pushing things so that I understand correctly :)

remove the schemaPath

The JSDoc of the schemaPath and schema config values mention there needs to be at least one of the two, do you mean removing the schemaPath and not using schema or essentially switching to schema?

commented

Probably a JSDoc info to update, because schemaPath (optional, default: "./schema.graphql")
You should be able to comment all of it

Well, I will take the solution with C/ as this is currently the fastest way for me to get this annoying kink worked out.

Essentially, setting neither schemaPath, schema and watchSchema does not work, but setting both schemaPath and watchSchema makes it so that houdini watches from the watchSchema.url property, but writes the file to the filepath defined by schemaPath.

image

However, using this approach, you cannot reference in the schemaPath folders that do not exist as a nasty error pops up while trying to either use houdini pull-schema or starting the vite dev server. Either create the folder first, or use a generic name. My guess is that it is simply because houdini does not try to create missing folders while writing to the schemaPath specified.

Welp, I was trying to prevent using http polling since I had the file already in my filesystem, but working around vite's limitations is annoying for sure so this is the best solution so far.

Thanks for the pointers! You can close this issue if you want, or leave it up for a JSDoc clarification reminder :)

Although now I remember why I did want to use the schemaPath: CI build uses the auto-generated schema file from my api folder to prevent having to spin up an entire server just for the sake of generating the houdini runtime...

So I guess my issue is still not resolved...

commented

Because you put your generated frontend schema in ./$houdini, so gitignored.
If you don't gitignore it, it should be good.

Because you put your generated frontend schema in ./$houdini, so gitignored. If you don't gitignore it, it should be good.

Well, yes, I do gitignore my generated schema because I don't want to pollute my repo with auto-generated documents. A simple fix is to commit it indeed.

I think I'll look into using a file watcher that runs from a vscode task (I already have three, might as well patch this into one of them haha).

Just to properly understand, is there a command to make the vite plugin pick up the changes to the schema? If I run houdini generate on file change myself, the vite plugin does not pickup the changes... Should I try to send a restart command to vite somehow?

If you prefer, we can pop in the Discord server for a more direct chat, then I'll summarize what we say in here - I'm having a hard time wrapping my head around how the houdini cli and the vite plugin communicate together 😅

Summary of solution from discord chat :

With my particular setup, since I generate the schema file automatically, what I did was add a copy file directive to my api script that essentially copies the schema file toward the gitignored $houdini folder, making it available for the build context as discussed in #1234 (comment).

So yeah, solution B/ was the thing (for me) after all!

Git commit link for those interested (ignore the added defaultFragmentMasking: 'disable', line) : ved-websites/fullstacked@036b4af

Im going to close this since its gone a bit stale and we. are limited by vite's functionality