Skip to content

Template string interpolation in comment breaks loaded graphql asset #28

@vctr-dev

Description

@vctr-dev

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch graphql-import-loader@0.2.1 for the project I'm working on.

If there is a comment in the .graphql file e.g. ${FIELD} ${OPERATOR}..., this breaks the generated file as it would treat them as a string interpolation due to backticks being used to wrap the export.

My solution is to replace ${ with \${, since $ is a valid symbol in graphql.

Here is the diff that solved my problem:

diff --git a/node_modules/graphql-import-loader/dist/src/index.js b/node_modules/graphql-import-loader/dist/src/index.js
index be4fa7b..ae741f9 100644
--- a/node_modules/graphql-import-loader/dist/src/index.js
+++ b/node_modules/graphql-import-loader/dist/src/index.js
@@ -4,7 +4,7 @@ var graphql_import_1 = require("graphql-import");
 function default_1(source) {
     var callback = this.async();
     this.cacheable();
-    callback(null, "module.exports = `" + graphql_import_1.importSchema(source).replace(/`/g, '\\`') + "`");
+    callback(null, "module.exports = `" + graphql_import_1.importSchema(source).replace(/`/g, '\\`').replace(/\${/g, '\\${') + "`");
 }
 exports.default = default_1;
 //# sourceMappingURL=index.js.map
\ No newline at end of file

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions