I'm not sure if this is me just not understanding how module import resolution works with whackage involved, or if there's a way to work around this, but here's the gist of what I'm seeing. I have a package that I'm developing that is intended to be used to share code across multiple similar apps. That said we have many graphql queries that will share fragments, and to avoid duplication I want to put them in the shared library.
Pseudo fragment:
// shared-fragments.js
import gql from 'graphql-tag';
export const sharedUserFields = gql`
fragment UserFields on User {
id
name
email
}
`;
// module index.js
export { sharedUserFields } from './shared-fragments';
This code works fine if the shared fragment is colocated in the consuming app itself, but what I'm seeing is that the sharedUserFields export is undefined at the time this code is executed, but if I import it later in the app (say at render time) it's exactly what I expect it to be. Unfortunately, any use of the graphql tag is also running at compile time and getting the same results.
Has anyone run into this issue? I'm guessing that once I publish this package and use it directly from node modules, this won't be an issue, but it causes a lot of pain in development when trying to develop the module and the app simultaneously using whack run start.
I'm not sure if this is me just not understanding how module import resolution works with whackage involved, or if there's a way to work around this, but here's the gist of what I'm seeing. I have a package that I'm developing that is intended to be used to share code across multiple similar apps. That said we have many graphql queries that will share fragments, and to avoid duplication I want to put them in the shared library.
Pseudo fragment:
Pseudo import in an app consuming this:
This code works fine if the shared fragment is colocated in the consuming app itself, but what I'm seeing is that the
sharedUserFields
export isundefined
at the time this code is executed, but if I import it later in the app (say at render time) it's exactly what I expect it to be. Unfortunately, any use of thegraphql
tag is also running at compile time and getting the same results.Has anyone run into this issue? I'm guessing that once I publish this package and use it directly from node modules, this won't be an issue, but it causes a lot of pain in development when trying to develop the module and the app simultaneously using
whack run start
.