UNPKG

@graphprotocol/graph-cli

Version:

CLI for building for and deploying to The Graph

39 lines (38 loc) 1.31 kB
import { URL } from 'node:url'; import * as toolbox from 'gluegun'; import Compiler from '../compiler/index.js'; import { GRAPH_CLI_SHARED_HEADERS } from '../constants.js'; import { createIpfsClient } from '../utils.js'; import { getGraphIpfsUrl } from './ipfs.js'; // Helper function to construct a subgraph compiler export function createCompiler(manifest, { ipfs, headers, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol, }) { // Validate the IPFS URL (if a node address was provided) try { if (ipfs && typeof ipfs === 'string') new URL(ipfs); } catch (e) { toolbox.print.error(`Invalid IPFS URL: ${ipfs} The IPFS URL must be of the following format: http(s)://host[:port]/[path]`); return null; } // Connect to the IPFS node (if a node address was provided) const ipfsClient = ipfs ? createIpfsClient({ url: getGraphIpfsUrl(ipfs.toString()).ipfsUrl, headers: { ...headers, ...GRAPH_CLI_SHARED_HEADERS, }, }) : undefined; return new Compiler({ ipfs: ipfsClient, subgraphManifest: manifest, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol, }); }