Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Added GraphQL #1461

Merged
merged 8 commits into from
May 19, 2019
Merged

Added GraphQL #1461

merged 8 commits into from
May 19, 2019

Conversation

MadelineMurray
Copy link
Contributor

Added GraphQL

Copy link
Contributor

@NicolasMassart NicolasMassart left a comment

Choose a reason for hiding this comment

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

Globally looks good, but I noted some differences between GraphQL and RPC requests that should be consistent IMO. It makes a lot of comments, but it's globally the same each time.

@@ -0,0 +1,27 @@
description: How to access the Pantheon API using GraphQL-RPC
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like "GraphQL-RPC". It may confuse people as it's not just JSON-RPC and you can change JSON by GraphQL, GraphQL is just another thing. The change was made in docs/Pantheon-API/Pantheon-API.md already so it's probably just an oversight here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I concur, GraphQL. Should I change package names too? I'll do it if you think it would help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


# GraphQL over HTTP

GraphQL can reduce the overhead needed for common queries. For example, instead of querying each receipt in a
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good explanation of the advantages but does not match the title that makes me expect specific things about making GraphQL requests over HTTP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NicolasMassart - Do you mean there's nothing about why you'd use GraphQL over HTTP specifically? HTTP is the only option for GraphQL. I thought about removing the transport method from the titles but have just recently specifically added it to make it it clearer the RPC Sub/Pub API is over WebSockets to make it more findable.

[Pantheon JSON-RPC API methods](../Reference/Pantheon-API-Methods.md) with an equivalent [GraphQL](../Pantheon-API/GraphQL.md)
query include a GraphQL request and result in the method example.

!!! example
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we just explaining in one line what this example request does : "Returns an result with data about the synchronization status" as it's described in the API ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

The third-party tool [GraphiQL](https://github.com/skevy/graphiql-app) provides a tabbed interface for editing and testing GraphQL
queries and mutations. GraphiQL also provides access the Pantheon GraphQL schema from within the app.

![GraphiQL](../images/GraphiQL.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

The screenshot should display the same query as in cURL request for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

## RPC Hosts

Use the [`--rpc-http-host`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-host), [`--rpc-ws-host`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-host),
and [`--graphql-http-host`](../Reference/Pantheon-CLI-Syntax.md#graphql-http-host) options to specify the host on which the RPC listens.
Copy link
Contributor

Choose a reason for hiding this comment

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

As RPC and GraphQL are described here I suggest the generic term service instead of a specific one.

Suggested change
and [`--graphql-http-host`](../Reference/Pantheon-CLI-Syntax.md#graphql-http-host) options to specify the host on which the RPC listens.
and [`--graphql-http-host`](../Reference/Pantheon-CLI-Syntax.md#graphql-http-host) options to specify the host on which the API service listens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

{
"data" : {
"account" : {
"code" : "0x608060405260043610610051576000357c010000000000000000000000000000000000000000000000000000000090048063010fc842146100565780630718e0ad146100815780637b8d56e3146100ac575b600080fd5b34801561006257600080fd5b5061006b6100f1565b6040518082815260200191505060405180910390f35b34801561008d57600080fd5b506100966100f7565b6040518082815260200191505060405180910390f35b3480156100b857600080fd5b506100ef600480360360408110156100cf57600080fd5b8101908080359060200190929190803590602001909291905050506100fd565b005b60005481565b60015481565b8160008190555080600181905550817fd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8826040518082815260200191505060405180910390a2505056fea165627a7a72305820badb5d43679c5579ebc76394df6e60b3e93a05481167e24711205dae2023edd70029"
Copy link
Contributor

Choose a reason for hiding this comment

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

and have the same result:

Suggested change
"code" : "0x608060405260043610610051576000357c010000000000000000000000000000000000000000000000000000000090048063010fc842146100565780630718e0ad146100815780637b8d56e3146100ac575b600080fd5b34801561006257600080fd5b5061006b6100f1565b6040518082815260200191505060405180910390f35b34801561008d57600080fd5b506100966100f7565b6040518082815260200191505060405180910390f35b3480156100b857600080fd5b506100ef600480360360408110156100cf57600080fd5b8101908080359060200190929190803590602001909291905050506100fd565b005b60005481565b60015481565b8160008190555080600181905550817fd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8826040518082815260200191505060405180910390a2505056fea165627a7a72305820badb5d43679c5579ebc76394df6e60b3e93a05481167e24711205dae2023edd70029"
"code" : "0x60806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633fa4f2458114604d57806355241077146071575b600080fd5b348015605857600080fd5b50605f6088565b60408051918252519081900360200190f35b348015607c57600080fd5b506086600435608e565b005b60005481565b60008190556040805182815290517f199cd93e851e4c78c437891155e2112093f8f15394aa89dab09e38d6ca0727879181900360200190a1505600a165627a7a723058209d8929142720a69bde2ab3bfa2da6217674b984899b62753979743c0470a2ea70029"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -995,6 +1150,18 @@ To avoid exposing your private key, create signed transactions offline and send
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{ "query": "mutation {sendRawTransaction(data: \"0xf8670e8082520894f17f52151ebef6c7334fad080c5704d77216b732880de0b6b3a7640000801ca091c7ca57b4a93acc46d1d29a43abfb7af925f6f11ef0c641630bbc05cdf63ba2a06a9d03b8327de9c79b819f7a4096e3aee2fc56c1bf150857011e310631388807\")}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

use the same raw tx as in RPC:

Suggested change
curl -X POST -H "Content-Type: application/json" --data '{ "query": "mutation {sendRawTransaction(data: \"0xf8670e8082520894f17f52151ebef6c7334fad080c5704d77216b732880de0b6b3a7640000801ca091c7ca57b4a93acc46d1d29a43abfb7af925f6f11ef0c641630bbc05cdf63ba2a06a9d03b8327de9c79b819f7a4096e3aee2fc56c1bf150857011e310631388807\")}"}' http://localhost:8547/graphql
curl -X POST -H "Content-Type: application/json" --data '{ "query": "mutation {sendRawTransaction(data: \"0xf869018203e882520894f17f52151ebef6c7334fad080c5704d77216b732881bc16d674ec80000801ba02da1c48b670996dcb1f447ef9ef00b33033c48a4fe938f420bec3e56bfd24071a062e0aa78a81bf0290afbc3a9d8e9a068e6d74caa66c5e0fa8a46deaae96b0833\")}"}' http://localhost:8547/graphql

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -1029,6 +1196,24 @@ You can interact with contracts using [eth_sendRawTransaction or eth_call](../Us
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{block {number call (data : {from : \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\", to: \"0x69498dd54bd25aa0c886cf1f8b8ae0856d55ff13\", data :\"0x12a7b914\"}){data status}}}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this request is a bit different than the RPC one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to make these equivalent without spending some time on it. Will raise a separate JI and may or may not get to it before the release on Wednesday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -1151,6 +1350,37 @@ Returns information about the block by hash.
}
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{block (hash : \"0xb0efed1fc9326fee967cb2d845d4ebe57c5350a0670c8e86f8052dea6f219f92\") {number transactions{hash} timestamp difficulty totalDifficulty gasUsed gasLimit hash noce ommerCount logsBloom mixHash ommerHash extraData stateRoot receiptsRoot transactionCount transactionsRoot}}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to have the same request and results here too so we can compare both RPC and GraphQL queries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have raised https://pegasys1.atlassian.net/secure/RapidBoard.jspa?rapidView=38&view=planning&selectedIssue=PAN-2714 to deal with the wider issue of making all requests again a public network and making the same call for JSON-RPC and GraphQL in each case

@@ -1307,9 +1626,6 @@ Returns transaction information for the specified block number and transaction i

Object - [Transaction object](Pantheon-API-Objects.md#transaction-object), or `null` when no transaction is found.

!!!note
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing this node ? It seems important to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It felt like assumed knowledge for the intended audience but maybe not? Can discuss on our sync tonight.

Copy link
Contributor

@shemnon shemnon left a comment

Choose a reason for hiding this comment

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

Could a fourth tab be added that is just the raw GraphQL query "pretty printed"?

@@ -0,0 +1,27 @@
description: How to access the Pantheon API using GraphQL-RPC
Copy link
Contributor

Choose a reason for hiding this comment

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

I concur, GraphQL. Should I change package names too? I'll do it if you think it would help.

### eth_accounts

Returns a list of account addresses that the client owns.

!!!note
<<<<<<< HEAD:docs/Reference/JSON-RPC-API-Methods.md
Copy link
Contributor

Choose a reason for hiding this comment

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

This merge artifact needs to be resolved. I'm surprised git didn't complain about it when submitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is gone now

Copy link
Contributor Author

Choose a reason for hiding this comment

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



```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{ account ( address: \"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73\") { balance } }"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the network these queries are executed against specified anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. A lot of them are against a private network - I've now realised we should have examples from a public network and specify which one so they can be used as is. Have raised https://pegasys1.atlassian.net/browse/PAN-2714 for this task.

@@ -863,6 +961,21 @@ Returns the number of transactions in a block matching the specified block numbe
"result" : "0x8"
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{ "query": "{block(number:\"0x58a6\"){transactionCount}}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not just ease of writing, this is correctness to the GraphQL spec, the number argument should be an integer not a hex string.

@@ -1344,6 +1660,25 @@ Object - [Transaction object](Pantheon-API-Objects.md#transaction-object), or `n
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:\"0x4f4f\") {transactionAt(index: 0) {block{hash} hash}}}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

Number should not be a hex string:

Suggested change
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:\"0x4f4f\") {transactionAt(index: 0) {block{hash} hash}}}"}' http://localhost:8547/graphql
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:82990) {transactionAt(index: 0) {block{hash} hash}}}"}' http://localhost:8547/graphql

Result will need to be recalculated to be the same block number as JSON-RPC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to a number but haven't addressed the wider issue of being the same block number as JSON-RPC at this point. I've added this to the wider point to updating all requests to be against a public testnet and adding an overview about using Infura to access the endpoint. There's not GraphQL endpoints available on Infura yet so need to wait for these to be addd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have added that this specific method example needs updated to https://pegasys1.atlassian.net/browse/PAN-2714

@@ -1701,6 +2064,30 @@ Returns an array of [logs](../Using-Pantheon/Events-and-Logs.md) matching a spec
} ]
}
```

```bash tab="curl GraphQL request"
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:\"0x59fd\") {logs(filter:{topics:[[\"0xd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8\", \"0x0000000000000000000000000000000000000000000000000000000000000002\"]]}) {index topics data account{address} transaction{hash} }}}"}' http://localhost:8547/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a number not a hex string

Suggested change
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:\"0x59fd\") {logs(filter:{topics:[[\"0xd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8\", \"0x0000000000000000000000000000000000000000000000000000000000000002\"]]}) {index topics data account{address} transaction{hash} }}}"}' http://localhost:8547/graphql
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:23037) {logs(filter:{topics:[[\"0xd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8\", \"0x0000000000000000000000000000000000000000000000000000000000000002\"]]}) {index topics data account{address} transaction{hash} }}}"}' http://localhost:8547/graphql

But if we are matching the JSON-RPC calls I think it is

Suggested change
curl -X POST -H "Content-Type: application/json" --data '{"query": "{block(number:\"0x59fd\") {logs(filter:{topics:[[\"0xd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8\", \"0x0000000000000000000000000000000000000000000000000000000000000002\"]]}) {index topics data account{address} transaction{hash} }}}"}' http://localhost:8547/graphql
curl -X POST -H "Content-Type: application/json" --data '{"query": "{blocks(from:0) {logs(filter:{topics:[[\"0xd3610b1c54575b7f4f0dc03d210b8ac55624ae007679b7a928a4f25a709331a8\", \"0x0000000000000000000000000000000000000000000000000000000000000002\"]]}) {index topics data account{address} transaction{hash} }}}"}' http://localhost:8547/graphql

However that might be a too-large query for the server based on how GraphQL queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

LGTM

@MadelineMurray MadelineMurray merged commit 26451f6 into PegaSysEng:master May 19, 2019
@MadelineMurray MadelineMurray deleted the graphQL branch May 19, 2019 23:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants