How to use the relay-compiler/lib/GraphQLIRPrinter.print function in relay-compiler

To help you get started, weโ€™ve selected a few relay-compiler 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 n1ru4l / graphql-codegen-relay-plugins / packages / graphql-codegen-relay-plugin / index.js View on Github external
if (!config.withFragmentContainer) {
      return "";
    }
    let queryName = doc.name.split("_")[0];
    if (!queryName) {
      return "";
    }
    const query = queryDocuments.find(query => query.name === queryName);

    if (!query) {
      console.warn(
        `Fragment '${doc.name}' uses relay notation but no query was found.`
      );
      return "";
    }
    const queryAst = parse(GraphQLIRPrinter.print(query));

    // @TODO: there might be multiple selection paths that use this fragment
    // build path on generated type
    const selectionPath = [];
    let currentSelectionSet = null;

    visit(queryAst, {
      enter: (node, key, parent) => {
        if (node.kind === "SelectionSet") {
          currentSelectionSet = node;
          if (parent.kind === "OperationDefinition") {
            selectionPath.push({
              type: "query",
              name: parent.name.value
            });
          } else {
github n1ru4l / graphql-codegen-relay-plugins / packages / graphql-codegen-relay-plugin / index.js View on Github external
const newQueryDocuments = queryCompilerContext.documents().map(doc => ({
    filePath: "optimized by relay",
    content: parse(GraphQLIRPrinter.print(doc))
  }));
github gatsbyjs / gatsby / packages / gatsby / src / internal-plugins / query-runner / query-compiler.js View on Github external
if (compiledNodes.has(filePath)) {
        let otherNode = compiledNodes.get(filePath)
        this.reportError(
          multipleRootQueriesError(
            filePath,
            nameDefMap.get(name),
            otherNode && nameDefMap.get(otherNode.name)
          )
        )
        return
      }

      let text = filterContextForNode(printContext.getRoot(name), printContext)
        .documents()
        .map(GraphQLIRPrinter.print)
        .join(`\n`)

      const query = {
        name,
        text,
        originalText: nameDefMap.get(name).text,
        path: filePath,
        isHook: nameDefMap.get(name).isHook,
        isStaticQuery: nameDefMap.get(name).isStaticQuery,
        hash: nameDefMap.get(name).hash,
      }

      if (query.isStaticQuery) {
        query.jsonName =
          `sq--` +
          _.kebabCase(