3 ms·
JSON here is used as a structured format, with clear specification. Graphql query also has specification, and you can encode it with JSON format, too. WHy not
by revskill 7y ago
JSON here is used as a structured format, with clear specification.
Graphql query also has specification, and you can encode it with JSON format, too.
WHy not ?
- underwater 7y agoWhat do you mean by structured? How is GraphQL structured Would you consider something like PHP's serialize() function to be structured? serialize(array('1' => 'elem 1', '2'=> 'elem 2', '3'=> 'elem 3')); // a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:6:"elem 3";} There are a lot of advantages to creating a custom syntax. In your example what does `query: { user: { id: 1, name: "true", } }` yield? How do you represent fragments? How do you represent variables and directives? You could implement conventions like `$ref`s in JSON schema, but then you've ended up creating another custom syntax... just this time it's piggy backing on JSON instead of plain text.
- baq 7y agoparse the query, emit ast as json, done. to me one of the important points of graphql is that it isn't json.