If I wanted to get 100 of your most recent posts for instance, I'd query for them like this:
query items(name: 'elvismercury', limit: 100) { id createdAt title text }
curl --request POST \ --header 'content-type: application/json' \ --url 'https://stacker.news/api/graphql' \ --data "{\"query\":\"query { items(name: \\\"elvismercury\\\", limit: 100) { id createdAt title text }}\"}"
{"errors":[{"message":"Cannot query field \"id\" on type \"Items\".","locations":[{"line":1,"column":51}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}},{"message":"Cannot query field \"createdAt\" on type \"Items\".","locations":[{"line":1,"column":54}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}},{"message":"Cannot query field \"title\" on type \"Items\".","locations":[{"line":1,"column":64}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}},{"message":"Cannot query field \"text\" on type \"Items\".","locations":[{"line":1,"column":70}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}}]}
Thoughts? (for the sake of PoW, I tried to troubleshoot already, but I don't know what I'm doing, so I'll omit the flailing.)
reply
Oh I oversimplified that example (accidentally).
This should do it:
query items(name: 'elvismercury', sort: 'user', limit: 100) { items { id createdAt title text } }
reply
One more on all this stuff.
I wanted to play around with some queries without obsessing over how many \\ I need to escape quotes from bash, so I went here and put in the server you mentioned yesterday as the endpoint:
https://stacker.news/api/graphql
It can't connect. It seems like it should be able to connect, but maybe I'm doing something really dumb. If so, is there some other tool that would let me run queries in a less frictiony way that I could use?
reply
It's CORS most likely.
I'll embed the sandbox on my next deployment.
reply
That did indeed do it. Exciting!
reply
Edited because I forgot we have to include sort: user for back compat.
reply