Open shaneog opened 3 years ago
A deeper dive has led me to https://github.com/detrohutt/babel-plugin-import-graphql/blob/master/plugin/index.js#L19 which assumes that the plugin is acting on a file, and not the contents of a file.
I've fixed my issue by using babel.transformFileSync
and passing in the filename, rather than using babel.transform
and passing in the file contents.
I'll leave this issue open for your attention.
I am getting similar issue after upgrading react-native to 0.69.5 and babel "^7.18.6",
When testing using Jest, I receive the following error when running
babel.transform
. I am using the test code defined in the README of this plugin.I have put together the simplest possible reproduction of this here: https://github.com/shaneog/babel-transform-graphql-example
When Babel is run manually (
npx babel test/fixtures --out-dir dist
) the code is transpiled correctly (formatted for ease of viewing):Click to see the formatted, transpiled JS
```js var myImportedQuery = { kind: "Document", definitions: [ { kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "products" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [ { kind: "Field", name: { kind: "Name", value: "products" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [ { kind: "Field", name: { kind: "Name", value: "productId" }, arguments: [], directives: [], }, { kind: "FragmentSpread", name: { kind: "Name", value: "productFragment" }, directives: [], }, ], }, }, ], }, }, { kind: "FragmentDefinition", name: { kind: "Name", value: "productFragment" }, typeCondition: { kind: "NamedType", name: { kind: "Name", value: "Product" }, }, directives: [], selectionSet: { kind: "SelectionSet", selections: [ { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [], }, { kind: "Field", name: { kind: "Name", value: "description" }, arguments: [], directives: [], }, { kind: "Field", name: { kind: "Name", value: "weight" }, arguments: [], directives: [], }, ], }, }, ], loc: { start: 0, end: 109, source: { body: '#import "./productFragment.graphql"\nquery products {\n products {\n productId\n ...productFragment\n }\n}\n', name: "GraphQL request", locationOffset: { line: 1, column: 1 }, }, }, }; ```This bug seems to be similar to #79.