-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate subgraph manifests using a GraphQL schema #147
Conversation
This algorithm validates a loaded subgraph manifest against a GraphQL schema that is shipped with Graph CLI.
@@ -70,7 +70,7 @@ class Compiler { | |||
try { | |||
return Subgraph.load(this.options.subgraphManifest) | |||
} catch (e) { | |||
throw Error('Failed to load subgraph') | |||
throw Error(`Failed to load subgraph: ${e.message}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this!! I was adding it myself any time I got that error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know 👍
@graphprotocol/developers Any suggestions for a better output formatting would be appreciated. What we have to play with are:
We could add more hints if we want. |
src/subgraph.js
Outdated
let yaml = require('js-yaml') | ||
let graphql = require('graphql/language') | ||
//let validate = require('@graphprotocol/graphql-data-validation') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to leave this commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, we want to remove it.
I think that's good! Could we add a line of code, or a method name? |
@nenadjaja I'm not sure what you mean by method name. I looked into YAML parsers that contain line/column information. They all only provide character start/end positions through YAML ASTs. It would be quite a lot of code to perform the validation using YAML ASTs. I'd rather keep it simple and perform the validation using JS data structures for now, since we may not even use YAML in the final version. |
I've updated the error formatting a little: Value with incorrect type➜ ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph: Error in subgraph.yaml:
Path: / > specVersion
Expected string, found list:
- 1
- 2 ➜ ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph: Error in subgraph.yaml:
Path: / > dataSources
Expected list, found map:
kind: ethereum/contract
name: ENSRegistrar
source:
address: '0x314159265dd8dbb310642f98f50c066173c1259b'
abi: EnsRegistrar
mapping:
kind: ethereum/events
apiVersion: 0.0.1
language: wasm/assemblyscript
file: ./src/ensRegistrar.ts
entities:
- EnsDomain
- Transfer
abis:
- name: EnsRegistrar
file: ./abis/EtherscanAbi.json
eventHandlers:
- event: 'Transfer(bytes32,address)'
handler: transfer
- event: 'NewOwner(bytes32,bytes32,address)'
handler: newOwner Missing file➜ ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph: Error in subgraph.yaml:
Path: / > schema > file
File does not exist: ./schema.graphql1 Missing value➜ ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph: Error in subgraph.yaml:
Path: / > dataSources > 0 > name
No value provided |
@graphprotocol/developers Could you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice, works great!
This validates subgraph manifests when loading them, using a GraphQL schema (manifest-schema.graphql).
We'll want to perform more validation for the GraphQL schema, the ABIs and the mappings. I'll create an epic for this.
Some of the error messages this generates:
Value with incorrect type
Missing file
Missing value