Skip to content
Open
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
16 changes: 8 additions & 8 deletions packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ To enable GQL requests caching:
yarn job-runner
```

* Run the server:

```bash
yarn server
```

GQL console: http://localhost:{{port}}/graphql

* To watch a contract:

```bash
Expand All @@ -137,6 +129,14 @@ To enable GQL requests caching:
yarn watch:contract --address MyProtocol --kind protocol --checkpoint true
```

* Run the server:

```bash
yarn server
```

GQL console: http://localhost:{{port}}/graphql

* To fill a block range:

```bash
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/utils/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { loadFilesSync } from '@graphql-tools/load-files';
import { ASSET_DIR } from './constants';

const GRAPH_TS_VERSION = '0.27.0-watcher-ts-0.1.3';
const GRAPH_CLI_VERSION = '0.32.0-watcher-ts-0.1.3';
const GRAPH_CLI_VERSION = '0.32.0-watcher-ts-0.1.4';

export function parseSubgraphSchema (subgraphPath: string, subgraphConfig: any): any {
const subgraphSchemaPath = path.join(path.resolve(subgraphPath), subgraphConfig.schema?.file ?? './schema.graphql');
Expand Down
30 changes: 25 additions & 5 deletions packages/codegen/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,35 @@ export class Visitor {
const name = node.name;
assert(name);

const params = node.parameters.map((item: any) => {
return { name: item.name, type: item.typeName.name };
const params = node.parameters.map((item: any, index: number) => {
const itemName = item.name ?? `arg${index}`;
return { name: itemName, type: item.typeName.name };
});

let errorMessage = '';

// Check for unhandled return type params
node.returnParameters.forEach(returnParameter => {
assert(returnParameter.typeName);

const isTypeHandled = ['ElementaryTypeName', 'ArrayTypeName'].includes(returnParameter.typeName.type);

if (!isTypeHandled) {
const errorMessage = `No support in codegen for type ${returnParameter.typeName.type} from method "${node.name}"`;
errorMessage = `No support in codegen for type ${returnParameter.typeName.type} from method "${node.name}"`;

if (this._continueOnError) {
console.log(errorMessage);
return;
}

throw new Error(errorMessage);
}
});

if (this._continueOnError && errorMessage !== '') {
console.log(errorMessage);
return;
}

this._schema.addQuery(name, params, node.returnParameters);
this._resolvers.addQuery(name, params);
assert(this._contract);
Expand Down Expand Up @@ -125,12 +133,24 @@ export class Visitor {
// If the variable type is mapping, extract key as a param:
// Eg. mapping(address => mapping(address => uint256)) private _allowances;
while (typeName.type === 'Mapping') {
assert(typeName.keyType.type === 'ElementaryTypeName', 'UserDefinedTypeName map keys like enum type not handled');
if (typeName.keyType.type === 'UserDefinedTypeName') {
errorMessage = 'No support in codegen for user defined type map keys';
break;
}

params.push({ name: `key${numParams.toString()}`, type: typeName.keyType.name });
typeName = typeName.valueType;
numParams++;
}

if (typeName.type === 'UserDefinedTypeName') {
errorMessage = 'No support in codegen for user defined type map values';
}

if (errorMessage !== '') {
break;
}

// falls through
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graph-node/test/subgraph/example1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
},
"dependencies": {
"@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3",
"@cerc-io/graph-cli": "0.32.0-watcher-ts-0.1.3"
"@cerc-io/graph-cli": "0.32.0-watcher-ts-0.1.4"
}
}
Loading