Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute imports possible? #99

Open
philr35 opened this issue Jul 21, 2019 · 1 comment
Open

Absolute imports possible? #99

philr35 opened this issue Jul 21, 2019 · 1 comment

Comments

@philr35
Copy link

philr35 commented Jul 21, 2019

I was wondering if absolute imports are possible. It does not seem like they work properly in create-react-app with the loader

I'm currently doing this which is not ideal:

const ADD_BOOK = loader("../../../../queries/book/list/add_book.gql");
const ALL_BOOKS = loader("../../../../queries/book/list/book_list.gql");

Any way to make this a non-relative import? I have absolute imports set for my create-react-app, but it does not work with the loader.

I would like to be able to do this:

const ADD_BOOK = loader("queries/book/list/add_book.gql");
const ALL_BOOKS = loader("queries/book/list/book_list.gql");

Any advice would be appreciated, thanks!

@tubbo
Copy link

tubbo commented Oct 15, 2020

I have a similar issue. Using yarn workspace to separate the API, data layer (all the GraphQL stuff), and UI. The packages are all @scoped so they have names like @my-app/api and @my-app/data.

In the UI, generated by Create React App, I have the following:

const HelloWorld = loader('@my-app/data/queries/hello-world.gql')

When this is executed, I get the following error:

Error: /Users/tscott/Code/my-app/ui/src/home.js: graphql.macro: ENOENT: no such file or directory, open '/Users/tscott/Code/my-app/ui/node_modules/@my-app/data/queries/hello-world.gql' Learn more: https://www.npmjs.com/package/graphql.macro

I believe this is due to the fact that Yarn workspaces have a top-level node_modules/ directory, and graphql.macro is looking in the wrong place for the dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants