Giter VIP home page Giter VIP logo

Comments (6)

dthyresson avatar dthyresson commented on August 18, 2024

Hi @shivghai turns out that @orta has similar experiences with his larger app as well ... and has invested some time in implementing hot module reloading (HMR) on the api/graphql side (still a WIP). He can provide more context, but perhaps we can offer a better experience soon.

from redwood.

shivghai avatar shivghai commented on August 18, 2024

@dthyresson Is there a thread I can follow? What do you recommend as next steps?

from redwood.

shivghai avatar shivghai commented on August 18, 2024

I'm happy to help with the implementation too, this is painful enough

from redwood.

orta avatar orta commented on August 18, 2024

No issue/thread to follow (#9738 relates because it's been my problem), I've mainly been prototyping outside of Redwood but the current runtime mechanics can be switched to remove the build step by moving to vite via: vite-node

Looking roughly like:

vite-node --watch src/server.ts
const schemas = import.meta.glob("./graphql/**/*.sdl.ts", { eager: true })
const services = import.meta.glob("./services/**/*.ts", { eager: true })

const fastify = Fastify({ logger: true })

const { yoga, logger } = createGraphQLYoga({
  allowGraphiQL: true,
  loggerConfig: {
    logger: createLogger({}),
  },
  services: services as any,
  sdls: schemas as any,
})

// [...]


function killServer() {
  if (!_fastify) return

  _fastify.close(() => {
    console.error("Reset graphql")
  })
}

// @ts-ignore
if (import.meta.hot) {
  // @ts-ignore
  const hot = import.meta.hot
  hot.on("vite:beforeFullReload", () => {
    console.log("HMR: full reload")
    killServer()
  })

  hot.dispose(() => {
    console.log("HMR: dispose")
    killServer()
  })
}

At a guess, to pull this off in Redwood would require:

  • understanding how to safely stop using the current dev server
  • figure out a watcher for files which need updating, that are currently in the build process
  • make a codemod for changing the users user-land graphql function code to use vite-node compatible import syntax instead of the babel modifications

from redwood.

dthyresson avatar dthyresson commented on August 18, 2024

Thanks @orta !

@Josh-Walker-GM and @Tobbe - any thoughts on how we might get api/gql side hmr in dev server?

from redwood.

orta avatar orta commented on August 18, 2024

I have a more fleshed out working version of HMR in https://github.com/orta/redwood-vite-api

from redwood.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.