How to use the graphql-tag.apply function in graphql-tag

To help you get started, we’ve selected a few graphql-tag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github VulcanJS / Vulcan / packages / nova-lib / lib / modules / fragments.js View on Github external
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);
}
github VulcanJS / Vulcan / packages / vulcan-lib / lib / modules / fragments.js View on Github external
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);
}
github LessWrong2 / Lesswrong2 / packages / vulcan-lib / lib / modules / fragments.js View on Github external
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);
};

graphql-tag

A JavaScript template literal tag that parses GraphQL queries

MIT
Latest version published 3 years ago

Package Health Score

83 / 100
Full package analysis

Similar packages