Skip to content

Commit

Permalink
fix(resolveImportPath): should work with relative path issue #52 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
evenchange4 committed Jan 25, 2019
1 parent aaa58c6 commit 3dad22f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
77 changes: 77 additions & 0 deletions src/__tests__/__snapshots__/macro.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,83 @@ const query = {
`;

exports[`macros [loader] should work with relative path issue#52: [loader] should work with relative path issue#52 1`] = `
import { loader } from 'graphql.macro';
const query = loader('../__tests__/fixtures/query.graphql');
↓ ↓ ↓ ↓ ↓ ↓
const query = {
"kind": "Document",
"definitions": [{
"kind": "OperationDefinition",
"operation": "query",
"name": {
"kind": "Name",
"value": "User"
},
"variableDefinitions": [],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [{
"kind": "Field",
"name": {
"kind": "Name",
"value": "user"
},
"arguments": [{
"kind": "Argument",
"name": {
"kind": "Name",
"value": "id"
},
"value": {
"kind": "IntValue",
"value": "5"
}
}],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [{
"kind": "Field",
"name": {
"kind": "Name",
"value": "firstName"
},
"arguments": [],
"directives": []
}, {
"kind": "Field",
"name": {
"kind": "Name",
"value": "lastName"
},
"arguments": [],
"directives": []
}]
}
}]
}
}],
"loc": {
"start": 0,
"end": 62,
"source": {
"body": "query User {\\n user(id: 5) {\\n firstName\\n lastName\\n }\\n}\\n",
"name": "GraphQL request",
"locationOffset": {
"line": 1,
"column": 1
}
}
}
};
`;

exports[`macros [loader] with absolute path and NODE_PATH: [loader] with absolute path and NODE_PATH 1`] = `
import { loader } from 'graphql.macro';
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/macro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ pluginTester({
const query = loader('./fixtures/query3.graphql');
`,
},
'[loader] should work with relative path issue#52': {
error: false,
code: `
import { loader } from '../macro';
const query = loader('../__tests__/fixtures/query.graphql');
`,
},
// '[loader] multiple operations': {
// error: false,
// code: `
Expand Down
2 changes: 1 addition & 1 deletion src/utils/resolveImportPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const resolveImportPath = ({
filename: string,
relativePath: string,
}): string => {
if (relativePath.startsWith('./')) {
if (relativePath.startsWith('.')) {
return path.join(filename, '..', relativePath);
}

Expand Down

0 comments on commit 3dad22f

Please sign in to comment.