Sha256: 9ee91162cb613e7281a1984a46bef62cc0f53195d5001cb0a518a690a1bec289

Contents?: true

Size: 980 Bytes

Versions: 38

Compression:

Stored size: 980 Bytes

Contents

/* eslint-env node */
const gql = require("graphql-tag");

// Takes `source` (the source GraphQL query string)
// and `doc` (the parsed GraphQL document) and tacks on
// the imported definitions.
const expandImports = (source) => {
  const lines = source.split("\n");
  let outputCode = "";

  lines.some((line) => {
    if (line[0] === "#" && line.slice(1).split(" ")[0] === "import") {
      const importFile = line.slice(1).split(" ")[1];
      const parseDocument = `require(${importFile})`;
      const appendDef = `doc.definitions = doc.definitions.concat(${parseDocument}.definitions);`;
      outputCode += `${appendDef}\n`;
    }
    return (line.length !== 0 && line[0] !== "#");
  });

  return outputCode;
}

module.exports = {
  process(src) {
    const doc = gql`${src}`;
    const outputCode = `var doc = ${JSON.stringify(doc)};`;
    const importOutputCode = expandImports(src, doc);

    return `${outputCode}\n${importOutputCode}\nmodule.exports = doc;`;
  }
};

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
decidim-comments-0.23.6 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.5 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.4 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.3 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.2 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.1.rc1 app/frontend/support/graphql_transformer.js
decidim-comments-0.23.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.22.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.21.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.20.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.20.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.19.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.18.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.19.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.17.2 app/frontend/support/graphql_transformer.js
decidim-comments-0.18.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.17.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.16.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.17.0 app/frontend/support/graphql_transformer.js