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

fragments absolute paths executed as relative in gql files under react unit test (chai) #43

Open
hichriHoussem opened this issue Jul 11, 2018 · 2 comments

Comments

@hichriHoussem
Copy link

So running a chai test on a react component that require a gql file (graphQL query)

#import "src/gql/fragments/activity/activityList.gql"
query getActivities($page: Int, $pageSize: Int) {
  getActivities(page: $page, pageSize: $pageSize) {
  ...activityListInfo
 }
}

the npm script:

"test:unit": "NODE_ENV=test NODE_PATH=./ mocha --require babel-core/register --require ignore-styles --require ./test/index.js --require ./test/dom.js './test/**/*.spec.js'"

as you can see the gql document importing a fragment for the schema the problem is that when i run the test the gql file is trying to take the fragment path as a relative so it look for the file in the wrong location path= 'path_to_gql_schema/path_to_gql_fragment' So I got a no such file or directory error, which can be solved with changing the fragment path to relative.

how can we fix that without changing all gql files fragments path to relative (about a handred) ?

@detrohutt
Copy link
Owner

detrohutt commented Jul 11, 2018

My #import implementation doesn't currently respect the NODE_PATH setting, so the path you used above would be relative to the .gql file.

My personal solution would be to use a "Find and replace in project" (I use Atom editor) with a regex pattern to correct the imports by prepending ../ or whatever depending on what level your .gql files are relative to the src folder. Hopefully most of them are At the same depth and you can fix the remaining ones manually. Depending on your folder structure this may not be helpful, but that's the only idea I have. 🙁

@clemmy
Copy link

clemmy commented Aug 1, 2019

I have a similar issue, but I think this is also an issue with fragments coming from a node_module. Unfortunately, the workaround with manually prepending ../ doesn't always work.
Consider the following scenario:

A imports B
A imports C
C imports B

where B is the GQL fragment

Since npm install may dedupe the installation, then B would only exist in the node_module of A, and C should technically resolve B from A's node_modules, but because it's resolved as a relative, it'll be trying to reference a non-existing dependency of C.

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

3 participants