Skip to content

Add GraphQL GET support for subgraph endpoints #2851

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

Open
raugfer opened this issue Oct 7, 2021 · 6 comments
Open

Add GraphQL GET support for subgraph endpoints #2851

raugfer opened this issue Oct 7, 2021 · 6 comments
Assignees

Comments

@raugfer
Copy link

raugfer commented Oct 7, 2021

Do you want to request a feature or report a bug?

I understanding it as bug, since GET requests should be supported by GraphQL compatible services.

https://graphql.org/learn/serving-over-http/#http-methods-headers-and-body

What is the current behavior?

Currently when accessing a subgraph URL using a GET request one gets redirected to /graphql (which is expected), however the /graphql handler does not work as expected.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Here is an example:

curl \
  --data '{"query":"query{signals(where:{id:\"0xb855e1847f49326ea13daeb454707faf4577604828827a780a81620000c4c2cf\"}){timestamp}}"}' \
  'https://api.thegraph.com/subgraphs/id/QmXe1SyxVqha6ipb8d3hht4WZaVzy43MUVXLoqXvYrb9dX'

Returns:

{"data":{"signals":[{"timestamp":"1632414153"}]}}

The same is expected to but is not returned by:

curl \
  'https://api.thegraph.com/subgraphs/id/QmXe1SyxVqha6ipb8d3hht4WZaVzy43MUVXLoqXvYrb9dX/graphql?query=query%7Bsignals(where:%7Bid:%220xb855e1847f49326ea13daeb454707faf4577604828827a780a81620000c4c2cf%22%7D)%7Btimestamp%7D%7D'

Here is a sample GraphQL URL that supports both modes:

POST

curl \
  -H "Content-Type: application/json" \
  --data '{"query":"{movies{name,genre}}"}' \
  'https://n7b67.sse.codesandbox.io/graphql'

GET

curl \
  'https://n7b67.sse.codesandbox.io/graphql?query=%7Bmovies%7Bname,genre%7D%7D'

What is the expected behavior?

GET requests should return the same results as POST requests. The difference is that the payload is passed in the URL's query string of the GET request, instead of the POST body.

@schmidsi
Copy link
Contributor

schmidsi commented Oct 7, 2021

I like this. That would be the first step of using The Graph as the endpoint for ERC721s tokenURI.

@azf20
Copy link
Contributor

azf20 commented Oct 20, 2021

Thanks @raugfer! Will take away and review, need to verify what implementation would look like in Graph Node

@AStox
Copy link

AStox commented Feb 25, 2022

Ahh looks like @schmidsi and I are on the same page here. Would love to to be generating dynamic SVG tokenURIs on the fly with a subgraph endpoint someday. Watching this thread 👀

@dotansimha
Copy link
Contributor

Regarding GET requests, it is worth considering that tools like https://github.com/dolevf/graphql-cop consider GET calls as a vulnerability, due to CSRF (https://github.com/dolevf/graphql-cop/blob/20bf34fa249feefdd48c7176bb663f52e9a7466d/lib/tests/info_get_method_support.py#L7-L14).

Also worth mentioning that if at some point we'll implement SSE as a transport for GraphQL Subscriptions, we can use the GET calls as the base for EventSource protocol

@azf20
Copy link
Contributor

azf20 commented Apr 25, 2022

Interesting - I think CSRF for read operations on a subgraph is low risk, what do you think @dotansimha ?

@dotansimha
Copy link
Contributor

Interesting - I think CSRF for read operations on a subgraph is low risk, what do you think @dotansimha ?

Yeah, agree on that, especially because it's read-only, and variables are always specific to the Subgraph (so no secrets or anything passed there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

5 participants