Skip to content
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

Merged
merged 7 commits into from
Oct 11, 2018

Conversation

Jannis
Copy link
Contributor

@Jannis Jannis commented Oct 10, 2018

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

➜  ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph:

Error at specVersion:
Expected string, found list:
- 1
- 2
➜  ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph:

Error at 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:
    - Domain
    - 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 at schema/file:
File does not exist: ./schema.graphql1

Missing value

➜  ens-subgraph git:(master) ✗ graph build subgraph.yaml
Failed to load subgraph:

Error at dataSources/0/name:
No value provided

Jannis Pohlmann added 3 commits October 9, 2018 19:52
This algorithm validates a loaded subgraph manifest against a GraphQL
schema that is shipped with Graph CLI.
@Jannis Jannis self-assigned this Oct 10, 2018
@ghost ghost added the pending review label Oct 10, 2018
@Jannis Jannis requested review from Zerim and a team October 10, 2018 09:49
@Jannis Jannis changed the title Validate subgraph manifests when loading them using a GraphQL manifest schema Validate subgraph manifests using a GraphQL manifest schema Oct 10, 2018
@Jannis Jannis changed the title Validate subgraph manifests using a GraphQL manifest schema Validate subgraph manifests using a GraphQL schema Oct 10, 2018
@@ -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}`)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know 👍

@Jannis
Copy link
Contributor Author

Jannis commented Oct 10, 2018

@graphprotocol/developers Any suggestions for a better output formatting would be appreciated. What we have to play with are:

  1. The path of the field that was invalid (e.g. ["schema", "file"]).
  2. The error message.

We could add more hints if we want.

nenadjaja
nenadjaja previously approved these changes Oct 10, 2018
src/subgraph.js Outdated
let yaml = require('js-yaml')
let graphql = require('graphql/language')
//let validate = require('@graphprotocol/graphql-data-validation')
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@nenadjaja
Copy link
Contributor

@graphprotocol/developers Any suggestions for a better output formatting would be appreciated. What we have to play with are:

  1. The path of the field that was invalid (e.g. ["schema", "file"]).
  2. The error message.

We could add more hints if we want.

I think that's good! Could we add a line of code, or a method name?

@Jannis
Copy link
Contributor Author

Jannis commented Oct 11, 2018

@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.

@Jannis
Copy link
Contributor Author

Jannis commented Oct 11, 2018

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

@Jannis
Copy link
Contributor Author

Jannis commented Oct 11, 2018

@graphprotocol/developers Could you take another look?

Copy link
Collaborator

@leoyvens leoyvens left a 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!

@Jannis Jannis merged commit 54d5452 into master Oct 11, 2018
@ghost ghost removed the pending review label Oct 11, 2018
@Jannis Jannis deleted the jannis/subgraph-validation branch October 11, 2018 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants