How can you see what endpoints are supported? You linked here yesterday, but how to tell the things that you can ask for? For REST stuff you'd get a list of them; is it meant to be something I can infer somehow, based on the schema you provided?
These are all the item endpoints or queries in graphql terms.
extend type Query { items(sub: String, sort: String, type: String, cursor: String, name: String, when: String, from: String, to: String, by: String, limit: Int): Items item(id: ID!): Item pageTitleAndUnshorted(url: String!): TitleUnshorted dupes(url: String!): [Item!] related(cursor: String, title: String, id: ID, minMatch: String, limit: Int): Items search(q: String, sub: String, cursor: String, what: String, sort: String, when: String, from: String, to: String): Items auctionPosition(sub: String, id: ID, bid: Int!): Int! itemRepetition(parentId: ID): Int! }
reply
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 }
reply
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