function gql(stroke, ...args) { return stroke.reduce((p, n, i) => p + args[i-1] + n); } function join(orig, option) { let _option = option.split('\n').slice(2, -2); let _orig = orig.split('\n'); let result = _orig.slice(0, -2).concat(_option, _orig.slice(-2)); return result.join('\n') } function concat(...args) { let result = args .map(q => q.split('\n')) .reduce((acc, q) => acc.slice(0, -2).concat(q.slice(2, -2), acc.slice(-2))) .join('\n'); return result; } function join(orig, option) { let _option = option.split('\n').slice(2, -2); let _orig = orig.split('\n'); let result = _orig.slice(0, -2).concat(_option, _orig.slice(-2)); console.log(result.join('\n')); } const postType = gql` query PostType { posts (user: $user) { id, time } } `; const userType = gql` query UserType { user (id: $id) { id, lastLogin, username, } } `; console.log( concat(postType, userType) // join(postType, userType) ); // Results: // query PostType { // posts (user: $user) { // id, // time // } // user (id: $id) { // id, // lastLogin, // username, // } // }
(ваш голос учтен)