Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!fragment) {
throw new Error(`Fragment "${fragmentName}" not registered.`)
}
// pad the literals array with line returns for each subFragments
const literals = [fragment.fragmentText, ...fragment.subFragments.map(x => '\n')];
// console.log(`// getFragment: ${parentFragmentName ? parentFragmentName + ' > ' : ''}${fragmentName}`)
// console.log('fragmentText: ', fragment.fragmentText)
// console.log('subFragments:', fragment.subFragments)
// console.log('length:', fragment.subFragments.length)
// the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
const gqlArguments = [literals, ...fragment.subFragments.map(f => getFragment(f, fragmentName))];
return gql.apply(null, gqlArguments);
}
export const getFragmentObject = (fragmentText, subFragments) => {
// pad the literals array with line returns for each subFragments
const literals = subFragments ? [fragmentText, ...subFragments.map(x => '\n')] : [fragmentText];
// the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
const gqlArguments = subFragments ? [literals, ...subFragments.map(subFragmentName => {
// return subfragment's gql fragment
if (!Fragments[subFragmentName] || !Fragments[subFragmentName].fragmentObject) {
throw new Error(`Subfragment “${subFragmentName}” of fragment “${extractFragmentName(fragmentText)}” has not been initialized yet.`);
}
return Fragments[subFragmentName].fragmentObject;
})] : [literals];
return gql.apply(null, gqlArguments);
}
export const getFragmentObject = (fragmentText, subFragments) => {
// pad the literals array with line returns for each subFragments
const literals = subFragments ? [fragmentText, ...subFragments.map(x => '\n')] : [fragmentText];
// the gql function expects an array of literals as first argument, and then sub-fragments as other arguments
const gqlArguments = subFragments ? [literals, ...subFragments.map(subFragmentName => {
// return subfragment's gql fragment
if (!Fragments[subFragmentName] || !Fragments[subFragmentName].fragmentObject) {
throw new Error(`Subfragment “${subFragmentName}” of fragment “${extractFragmentName(fragmentText)}” has not been initialized yet.`);
}
return Fragments[subFragmentName].fragmentObject;
})] : [literals];
return gql.apply(null, gqlArguments);
};