Need to parse the incoming JSON query and.Serving a JSON DSL based API requires that you: However, what is the “swagger” equivalent for a single HTTP endpoint that takes our JSON query? A query language follows a “grammar” and not really a “shape”. For example, a “swagger” specification of your API would look like this: This allows the creation of things like a “swagger” spec. The JSON that is sent back and forth adheres to a “shape” or a skeleton but not really a dynamic query language. With a REST-ish design, there’s no query language. But in a custom JSON DSL what if the “query language” changes on the server side? How you do create a specification for the client to create queries in JSON that are valid? Where is the “grammar” of your JSON DSL? REST-ish endpoints propose a simple, if slightly ad-hoc, grammar with HTTP verbs and simple JSON being chucked back and forth. However, the JSON DSL approach has a few problems that start emerging when you deploy it over a long running software project or a large team. JSON objects can be easily manipulated, especially in a language like Javascript where JSON can easily be parsed into a Javascript object.ĭirectives and fragments in GraphQL would not even be required in JSON because you can just manipulate a POJO (plain old javascript object ?) exactly the way you need to.Is a JSON DSL actually a feasible alternative?įor example, a “read” query might look like this in GraphQL:īut if we were to use a custom JSON query language, we might have come up with this ourselves:Īs you can see, the JSON DSL is “uglier” but it’s a lot more flexible, no additional tooling and you can create your own “query language”. GraphQL killer-feature: Community tooling can thrive because of that design.GraphQL killer-design: API contract is a part of the code.GraphQL: Schema can be used by the client to create tooling that automatically validates queries or “codegen”s typesafe SDKs. GraphQL: Not just a query language but forces the server to publish a schema making the query/API spec a part of the code.A JSON DSL requires no change in client-side and server side tooling.A JSON DSL can be as expressive (actually too expressive) as GraphQL.The rise of GraphQL is also perhaps a signal of the increasing amount of “type safety” tooling in Javascript community. This fact coupled with the rise of server side tooling, is why a GraphQL system is something you should seriously look at if you’re thinking of writing a JSON based query language for your APIs. However, there is a singular feature of a GraphQL system that is the key differentiator: the GraphQL schema that is served by any GraphQL server. The first few times I came across GraphQL I was very skeptical of its benefits because the cost of putting together a GraphQL system seemed too high and it seemed to me that all the benefits of GraphQL could be gained by having a just creating a custom JSON DSL (a query language using JSON). GraphQL is awesome but I didn’t always see it that way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |