Skip to content
Merged
6 changes: 6 additions & 0 deletions .changeset/@graphprotocol_graph-cli-1268-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphprotocol/graph-cli": patch
---
dependencies updates:
- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/ipfs-http-client/v/55.0.0) (from `34.0.0`, in `dependencies`)
- Updated dependency [`[email protected]` ↗︎](https://www.npmjs.com/package/jayson/v/4.0.0) (from `3.7.0`, in `dependencies`)
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,5 @@
"eslint": "^8.31.0",
"jest": "26.6.3",
"prettier": "^2.8.2"
},
"pnpm": {
"overrides": {
"[email protected]>concat-stream": "github:mihirgupta0900/concat-stream#master"
}
}
}
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
"graphql": "15.5.0",
"immutable": "4.2.1",
"ipfs-http-client": "34.0.0",
"jayson": "3.7.0",
"ipfs-http-client": "55.0.0",
"jayson": "4.0.0",
"js-yaml": "3.14.1",
"prettier": "1.19.1",
"request": "2.88.2",
Expand Down
17 changes: 4 additions & 13 deletions packages/cli/src/command-helpers/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'url';
import * as toolbox from 'gluegun';
import ipfsHttpClient from 'ipfs-http-client';
import { create } from 'ipfs-http-client';
import Compiler from '../compiler';
import Protocol from '../protocols';

Expand All @@ -27,26 +27,17 @@ export function createCompiler(
protocol,
}: CreateCompilerOptions,
) {
// Parse the IPFS URL
let url;
// Validate the IPFS URL (if a node address was provided)
try {
url = ipfs ? new URL(ipfs) : undefined;
if (ipfs) 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)
ipfs = ipfs
? ipfsHttpClient({
protocol: url?.protocol.replace(/[:]+$/, ''),
host: url?.hostname,
port: url?.port,
'api-path': url?.pathname.replace(/\/$/, '') + '/api/v0/',
headers,
})
: undefined;
ipfs = ipfs ? create({ url: ipfs, headers }) : undefined;

return new Compiler({
ipfs,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/command-helpers/ipfs-http-client.d.ts

This file was deleted.

18 changes: 14 additions & 4 deletions packages/cli/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Protocol from '../protocols';
import Subgraph from '../subgraph';
import Watcher from '../watcher';
import * as asc from './asc';
import type { IPFSHTTPClient } from 'ipfs-http-client';

const compilerDebug = debug('graph-cli:compiler');

Expand All @@ -26,7 +27,7 @@ interface CompilerOptions {
}

export default class Compiler {
private ipfs: any;
private ipfs: IPFSHTTPClient;
private sourceDir: string;
private blockIpfsMethods?: RegExpMatchArray;
private libsDirs: string[];
Expand Down Expand Up @@ -678,9 +679,18 @@ export default class Compiler {

async _uploadToIPFS(file: { path: string; content: Buffer }) {
try {
const hash = (await this.ipfs.add([file]))[0].hash;
await this.ipfs.pin.add(hash);
return hash;
const files = this.ipfs.addAll([file]);

// We get back async iterable
const filesIterator = files[Symbol.asyncIterator]();
// We only care about the first item, since that is the file, rest could be directories
const { value } = await filesIterator.next();

// we grab the file and pin it
const uploadedFile = value as Awaited<ReturnType<typeof this.ipfs.add>>;
await this.ipfs.pin.add(uploadedFile.cid);

return uploadedFile.cid.toString();
} catch (e) {
throw Error(`Failed to upload file to IPFS: ${e.message}`);
}
Expand Down
Loading