Why We Advised Our Customer Against GraphQL
APIs are crucial to the ways developers access and use data. Read on for a discussion of why one team advised against the use of GraphQL to ingest data from APIs.
Join the DZone community and get the full member experience.Join For Free
graphql has captured a lot of developer interest over the last year or so with many production level systems making the switch from rest type apis to graphql. when one of our existing customers asked us to decide if we should switch their existing apis over to graphql, the team was pretty excited to finally get to work on this new style of api calls!
however, as we evaluated the technology and assessed its compatibility with the existing system, we decided to not make the switch. here is the case in consideration!
the existing system
- sql server db with sps, functions, views, and queries. sps are non-modular in the sense they join various tables and return values specific to the calls being made.
- connection with the db is using basic ado.net and not with ef/linq, etc.
- asp.net webapi2.0 (not .net core) and java-based apis.
- native android, ios and web clients. some portion of the web clients bypasses the api and talks to the db directly.
- webclients: asp.net and react.
- a react native-based app.
- system has been in production for few years now and is stable.
- as the system is in a competitive space, new features are always getting added apart from usual maintenance.
- whether it makes sense to wrap our existing apis into a graphql endpoint.
- for a new feature in the react app evaluate making the new .net based apis in graphql.
we finally got started with a combination of these blogs/articles!
- https://fullstackmark.com/post/17/building-a-graphql-api-with-aspnet-core-2-and-entity-framework-core (this is for .net core but good to get started).
- https://github.com/jacekkosciesza/starwars (again this is for .net core).
- https://graphql-dotnet.github.io/ (graphql for .net repo).
- https://github.com/graphql-dotnet/examples/tree/master/src/aspnetwebapi ( pretty much the only .net framework example we got and most useful!).
- we also wanted to use graphiql but the available nuget was again for .net core so we used the graphiql repo directly from https://github.com/graphql/graphiql .
with a good understanding of how the system will work we then implemented a couple of apis for the new system in graphql to see how it will fit in with the existing system.
for am existing call like
if the current sp returns only
and not the
, then a client call trying to access the child's parents name won't really return any data anyway, as it has no way to resolve the parent info.
- the new feature requirement could, as such, be implemented reusing a lot of the existing sps.
- in order to use graphql for these apis, however, we could not reuse the existing sps as graphql works best when we resolve one entity at a time rather than an sp which joins data across tables and returns a consolidated object. so this meant we would need to replicate the sps and mark them for use with graphql.
- even with the use of dataloader to optimize the db calls we would end up with a few more db hits than the existing approach where we make one call per api to a specific sp.
- the new feature request was pretty small and while a good candidate to get started with graphql it would cause code repetition and maintenance overhead if added with existing apis.
- on the client-side, also, the graphql code would be intermixed with calling older rest apis.
our suggestion to the customer
- while graphql is server agnostic and can work with any server implementation including the ability to wrap existing implementations under an endpoint, it is best utilized when the server-db interaction is per entity level so that each entity can get resolved independently.
- the existing system is working well and has been optimized heavily from a database point of view. re-wiring it and re-wiring all clients just to use graphql is not advisable at this time.
- the new feature which plugs into the existing system very closely is too small to add a new framework in the mix, will cause repetition of code functionality and a maintenance overhead.
- we should look to add graphql with the next big subsystem which is being planned which will involve new tables, new sps and a new set of apis.
with that we concluded our exercise and the team is looking forward to using graphql in a new subsystem that is being visualized! meanwhile we will work to put up a walkthrough of a sample graphql server on the .net framework with mutations and the works, and hopefully save a fellow .net developer some time.
Published at DZone with permission of Anshulee Asthana, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.