Hacker News new | ask | show | jobs
by aaroninsf 3936 days ago
Why mirror the structure, but not syntactic details, of JSON (or YML) in the pretty printing?

It's true that we've passed peak colon as a culture, and need to start reimagining life in a post-colonial way, but...

1 comments

GraphQL queries are hierarchical so that the response mirrors the structure of the query. We found that there were needs of the query (query parameters and directives, for example) that didn't feel ideally represented in JSON, which is why we have a different syntax.

We've got a reference lexer and parser in JS at https://github.com/graphql/graphql-js/tree/master/src/langua..., and we have a parser in C++ with C and C++ APIs (that can be used to build a parser for other languages) at https://github.com/graphql/libgraphqlparser.

Anecdote: when Relay/GraphQL were first announced, we tried to get Relay without GraphQL by writing JSON. This had some advantages (a query was a valid/renderable response!)

...but we had some really ugly JSON. It was worth it for us to get the readable syntax to just use GraphQL.

With client tooling like GraphiQL and editor plugins, it should just get better.