Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-ties-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Fix empty source name for substreams subgraphs #1868
23 changes: 10 additions & 13 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const protocolChoices = Array.from(Protocol.availableProtocols().keys());
const initDebugger = debugFactory('graph-cli:commands:init');

const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar';
const DEFAULT_CONTRACT_NAME = 'Contract';

export default class InitCommand extends Command {
static description = 'Creates a new subgraph with basic scaffolding.';
Expand Down Expand Up @@ -61,7 +62,7 @@ export default class InitCommand extends Command {
description: 'Creates a scaffold based on an example subgraph.',
// TODO: using a default sets the value and therefore requires not to have --from-contract
// default: 'Contract',
exclusive: ['from-contract'],
exclusive: ['from-contract', 'spkg'],
}),

'contract-name': Flags.string({
Expand Down Expand Up @@ -103,7 +104,6 @@ export default class InitCommand extends Command {
summary: 'Network the contract is deployed to.',
description:
'Refer to https://github.com/graphprotocol/networks-registry/ for supported networks',
dependsOn: ['from-contract'],
}),

ipfs: Flags.string({
Expand Down Expand Up @@ -143,17 +143,14 @@ export default class InitCommand extends Command {
'The --skip-git flag will be removed in the next major version. By default we will stop initializing a Git repository.',
);
}
if ((!fromContract || !spkgPath) && !network && !fromExample) {
this.error('--network is required when using --from-contract or --spkg');
}

const { node } = chooseNodeUrl({
node: nodeFlag,
});

if (fromContract && fromExample) {
this.error('Only one of "--from-example" and "--from-contract" can be used at a time.', {
exit: 1,
});
}

// Detect git
const git = system.which('git');
if (!git) {
Expand Down Expand Up @@ -200,7 +197,7 @@ export default class InitCommand extends Command {

// If all parameters are provided from the command-line,
// go straight to creating the subgraph from an existing contract
if (fromContract && protocol && subgraphName && directory && network && node) {
if ((fromContract || spkgPath) && protocol && subgraphName && directory && network && node) {
const registry = await loadRegistry();
const contractService = new ContractService(registry);

Expand All @@ -225,7 +222,7 @@ export default class InitCommand extends Command {
}
} else {
try {
abi = await contractService.getABI(ABI, network, fromContract);
abi = await contractService.getABI(ABI, network, fromContract!);
} catch (e) {
this.exit(1);
}
Expand All @@ -237,11 +234,11 @@ export default class InitCommand extends Command {
protocolInstance,
abi,
directory,
source: fromContract,
source: fromContract!,
indexEvents,
network,
subgraphName,
contractName,
contractName: contractName || DEFAULT_CONTRACT_NAME,
node,
startBlock,
spkgPath,
Expand Down Expand Up @@ -303,7 +300,7 @@ export default class InitCommand extends Command {
network: answers.network,
source: answers.source,
indexEvents: answers.indexEvents,
contractName: answers.contractName,
contractName: answers.contractName || DEFAULT_CONTRACT_NAME,
node,
startBlock: answers.startBlock,
spkgPath: answers.spkgPath,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/scaffold/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default class Scaffold {

async generateManifest() {
const protocolManifest = this.protocol.getManifestScaffold();
const name = this.contractName || getSubgraphBasename(String(this.subgraphName));

return await prettier.format(
`
Expand All @@ -128,7 +129,7 @@ schema:
file: ./schema.graphql
dataSources:
- kind: ${this.protocol.name}
name: ${this.contractName}
name: ${name}
network: ${this.network}
source: ${protocolManifest.source({ ...this, spkgPath: './substreams.spkg', spkgModule: 'graph_out' })}
mapping: ${protocolManifest.mapping(this)}
Expand Down
32 changes: 32 additions & 0 deletions packages/cli/tests/cli/__snapshots__/init.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,35 @@ Next steps:
Make sure to visit the documentation on https://thegraph.com/docs/ for further information.
"
`;

exports[`Init > Substreams > From package 1`] = `
" › Warning: The --skip-git flag will be removed in the next major version. By
› default we will stop initializing a Git repository.
- Create subgraph scaffold
Generate subgraph
- Create subgraph scaffold
Write subgraph to directory
- Create subgraph scaffold
✔ Create subgraph scaffold
- Install dependencies with yarn
✔ Install dependencies with yarn
"
`;

exports[`Init > Substreams > From package 2`] = `0`;

exports[`Init > Substreams > From package 3`] = `
"
Subgraph user/subgraph-from-substreams created in from-package

Next steps:

1. Run \`graph auth\` to authenticate with your deploy key.

2. Type \`cd from-package\` to enter the subgraph.

3. Run \`yarn deploy\` to deploy the subgraph.

Make sure to visit the documentation on https://thegraph.com/docs/ for further information.
"
`;
27 changes: 27 additions & 0 deletions packages/cli/tests/cli/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,33 @@ describe.sequential(
},
);
});

describe('Substreams', () => {
const substreamsBaseDir = path.join(baseDir, 'substreams');

cliTest(
'From package',
[
'init',
'--skip-git',
'--protocol',
'substreams',
'--spkg',
path.join(substreamsBaseDir, 'substreams.spkg'),
'--network',
'mainnet',
'user/subgraph-from-substreams',
path.join(substreamsBaseDir, 'from-package'),
],
path.join('init', 'substreams', 'from-package'),
{
exitCode: 0,
timeout: 100_000,
cwd: substreamsBaseDir,
deleteDir: true,
},
);
});
},
{
timeout: 60_000,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tests/cli/init/substreams/substreams.spkg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file, nothing to see here
Loading