Hey there,
I was just wondering what the best way is to get the current app version (my app version, not the RedwoodJS version) from package.json to display inside the UI of my web app?
With Create React App, I know people would build it with the $npm_package_version
and then it would be available through process.env
, but I haven’t seen anything like that available with RedwoodJS. Is there a convenient way to handle this, or do I need to make a custom GraphQL query to retrieve that information?
This seems like something that would be awesome to include in the root GraphQL query, alongside the Redwood version.
The way that I ended up doing this was using the current git tag rather than the npm package version. I was comfortable with this because I didn’t want to have to maintain different version numbers for the different sides of the application or anything like that, and this ended up just being easier.
Basically I changed my start command for my API to look like this, in the root package.json
file:
"start:api": "APP_VERSION=\"$(git describe --tag --abbrev=0)\" yarn rw deploy flightcontrol api --serve"
Then I added a graphql query called version
, the implementation for which looks like this:
export const version: QueryResolvers['version'] = () => {
return process.env.APP_VERSION
}
Then use that query wherever I want to display the version in the UI. I’m sure there are some slightly better ways to do this, but this works for my needs. Hopefully this helps someone at least get started if they want to do something similar!
1 Like