Sha256: 2e09034d054815841526c58b621504cdef0acac51de71fa537e9b22008bae325

Contents?: true

Size: 980 Bytes

Versions: 62

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

62 entries across 62 versions & 2 rubygems

Version Path
decidim-comments-0.10.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.10.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.9.3 app/frontend/support/graphql_transformer.js
decidim-comments-0.9.2 app/frontend/support/graphql_transformer.js
decidim-comments-0.9.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.9.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.8.4 app/frontend/support/graphql_transformer.js
decidim-comments-0.8.3 app/frontend/support/graphql_transformer.js
decidim-comments-0.8.2 app/frontend/support/graphql_transformer.js
decidim-comments-0.8.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.8.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.7.4 app/frontend/support/graphql_transformer.js
decidim-comments-0.7.3 app/frontend/support/graphql_transformer.js
decidim-comments-0.7.2 app/frontend/support/graphql_transformer.js
decidim-comments-0.7.1 app/frontend/support/graphql_transformer.js
decidim-comments-0.7.0 app/frontend/support/graphql_transformer.js
decidim-comments-0.6.8 app/frontend/support/graphql_transformer.js
decidim-0.6.8 decidim-comments/app/frontend/support/graphql_transformer.js
decidim-comments-0.6.7 app/frontend/support/graphql_transformer.js
decidim-0.6.7 decidim-comments/app/frontend/support/graphql_transformer.js