4 ms·
I hate to break it to you, but JSON is a string too. i.e. There is no such thing as a "JSON value" in JavaScript, just a method that will convert a subset of Ja
by underwater 7y ago
I hate to break it to you, but JSON is a string too. i.e. There is no such thing as a "JSON value" in JavaScript, just a method that will convert a subset of JavaScript primitives to a JSON string encoding.
GraphQL is a well-defined syntax that can be validated by both client and server. An invalid query can be rejected with a syntax error.
Yes, it is harder to dynamically construct a GraphQL query on the client, but you shouldn't do that anyway. The language has directives and variables that can introduce dynamic elements.
- revskill 7y agoJSON 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.