FormidableLabs / whackage

Multi-repo development tooling for React Native
MIT License
133 stars 16 forks source link

Module import resolution is "out of sync" #30

Open dphaener opened 6 years ago

dphaener commented 6 years ago

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';

Pseudo import in an app consuming this:

import { sharedUserFields } from 'my-shared-module';

export const query = gql`
  query UserQuery {
    user {
      ...UserFields
    }
  }
  ${sharedUserFields}
`;

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.