I have a legacy project which uses 700+ complex stored procedures to fetch and modify data. Is there a way to use Graphql to create an API without changing the stored procedures?
Depending on the language you are working in, there may be GraphQL libraries that are stored-procedure aware. If not, you can write your own.
You can also write a thin REST layer and layer GraphQL over that.
Edit:
If you're using ASP.NET Core, check out this library and follow the examples in their documentation's introduction page, except replace the hard-coded data with calls in the library you would usually use to communicate with SQL Server to fetch the required data. I recommend Dapper (it was actually written by the folks at Stack Overflow!) as it will let you write lightweight queries like conn.Query("[dbo].myFooProc @bar @baz", new { bar = quux, baz = 22 }) (or using whatever existing classes you have).
So ultimately your code would look something like
public class FooBarQuery : ObjectGraphType
{
public FooBarQuery()
{
var MyData = conn.Query("[dbo].myFooBarProc @FooId", new { FooId = 2 }).ToList();
Field<FooType>(
resolve: context => MyData;
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With