packages/gql-merge/dist/index.js
function mergeAst(schemaAst) {
  var typeDefs = {};

  // Go through the AST and extract/merge type definitions.
  var editedAst = (0, _language.visit)(schemaAst, {
    enter: function enter(node) {
      var nodeName = node.name ? node.name.value : null;

      // Don't transform TypeDefinitions directly
      if (!nodeName || !node.kind.endsWith('TypeDefinition')) {
        return;
      }

      var oldNode = typeDefs[nodeName];

      if (!oldNode) {
        // First time seeing this type so just store the value.
        typeDefs[nodeName] = node;
        return null;
      }

      // This type is defined multiple times, so merge the fields and values.
      var concatProps = ['fields', 'values', 'types'];
      concatProps.forEach(function (propName) {
        if (node[propName] && oldNode[propName]) {
          node[propName] = oldNode[propName].concat(node[propName]);
        }
      });

      typeDefs[nodeName] = node;
      return null;
    }
  });

  var remainingNodesStr = (0, _gqlFormat.formatAst)(editedAst);
  var typeDefsStr = (0, _values2.default)(typeDefs).map(_gqlFormat.formatAst).join('\n');
  var fullSchemaStr = remainingNodesStr + '\n\n' + typeDefsStr;

  return (0, _gqlFormat.formatString)(fullSchemaStr);
}
function mergeAst(schemaAst) {
  var typeDefs = {};

  // Go through the AST and extract/merge type definitions.
  var editedAst = (0, _language.visit)(schemaAst, {
    enter: function enter(node) {
      var nodeName = node.name ? node.name.value : null;

      // Don't transform TypeDefinitions directly
      if (!nodeName || !node.kind.endsWith('TypeDefinition')) {
        return;
      }

      var oldNode = typeDefs[nodeName];

      if (!oldNode) {
        // First time seeing this type so just store the value.
        typeDefs[nodeName] = node;
        return null;
      }

      // This type is defined multiple times, so merge the fields and values.
      var concatProps = ['fields', 'values', 'types'];
      concatProps.forEach(function (propName) {
        if (node[propName] && oldNode[propName]) {
          node[propName] = oldNode[propName].concat(node[propName]);
        }
      });

      typeDefs[nodeName] = node;
      return null;
    }
  });

  var remainingNodesStr = (0, _gqlFormat.formatAst)(editedAst);
  var typeDefsStr = (0, _values2.default)(typeDefs).map(_gqlFormat.formatAst).join('\n');
  var fullSchemaStr = remainingNodesStr + '\n\n' + typeDefsStr;

  return (0, _gqlFormat.formatString)(fullSchemaStr);
}
function mergeAst ( schemaAst ) { var typeDefs = { } ; // Go through the AST and extract/merge type definitions. var editedAst = ( 0 , _language . visit ) ( schemaAst , { enter : function enter ( node ) { var nodeName = node . name ? node . name . value : null ; // Don't transform TypeDefinitions directly if ( ! nodeName || ! node . kind . endsWith ( 'TypeDefinition' ) ) { return ; } var oldNode = typeDefs [ nodeName ] ; if ( ! oldNode ) { // First time seeing this type so just store the value. typeDefs [ nodeName ] = node ; return null ; } // This type is defined multiple times, so merge the fields and values. var concatProps = [ 'fields' , 'values' , 'types' ] ; concatProps . forEach ( function ( propName ) { if ( node [ propName ] && oldNode [ propName ] ) { node [ propName ] = oldNode [ propName ] . concat ( node [ propName ] ) ; } } ) ; typeDefs [ nodeName ] = node ; return null ; } } ) ; var remainingNodesStr = ( 0 , _gqlFormat . formatAst ) ( editedAst ) ; var typeDefsStr = ( 0 , _values2 . default ) ( typeDefs ) . map ( _gqlFormat . formatAst ) . join ( '\n' ) ; var fullSchemaStr = remainingNodesStr + '\n\n' + typeDefsStr ; return ( 0 , _gqlFormat . formatString ) ( fullSchemaStr ) ; }
Merges duplicate definitions in a single GraphQL abstract-syntax tree
@param {Document} schemaAst - The GraphQL AST.
@return {string} The resulting merged GraphQL string.
Merges duplicate definitions in a single GraphQL abstract - syntax tree