Hi all! Any good pointers on how to marry Prisma w...
# orm-help
p
Hi all! Any good pointers on how to marry Prisma with C# (.net core 2.2) web API and implement authorized graphql queries (i.e. client gets an error if tries to access some data or do mutation while not having a certain role/claim/etc.)?
a
You could build a prisma server that your .net api calls and have a graphql wrapper infront of the api. Use graphql-shield in the wrapper for restricted access. I would use an existing ORM like EF core with .net core and just use the graphql wrapper over top the api. That's just me though, I have not tried to connect Prisma with .net core yet. If you figure it out let me know would be interested to see what you came up with :)
p
Thanks @Austin Howlett! Am I right that you suggest to place an extra layer built with graphql-shield (and likely graphql-yoga) in front of my .net api so that the request first goes there, passes auth checks then gets passed to .net api and from there is passed to prisma server?
a
Yep that would be essentially it. Although I think using the graphql wrapper infront of the .net core api and using Entity Framework Core as the ORM instead of Prisma would be more beneficial.
I know you want to use Prisma but its seems like alot of extra complexity to just add a Prisma server. It is totally doable. I haven't looked it up to see if they will support .net integrations but if you come up with something as I said before I would be super interested to see what you come up with. Hopefully this helped a bit. :)
p
Thanks, I'll ping you if I'll come up with something meaningful. I am currently on EF and like it but there's an issue I bumped into and want to use prisma for. It is a dynamic filtering of query results based on nested objects. i.e. when there's an order and a collection of order items, I need to filter out orders by some properties of items in those orders. The problem is that exact set of filter rules is defined by a client app and is not known upfront so I need something that is able to construct queries dynamically and provide aggregate functions + pagination for these results. Not something EF can easily provide out of the box unfortunately... With Prisma however this is easily achievable via filter attributes in graphql queries. The problem is the rest of my API is already on .net and EF so I am trying to figure it out what is the best strategy I can implement to resolve this
f
@Peter Rogov did you come to some conclusion? I'll probably also use graphqdotnet and write my own filter parameters. Only the dataloader i think is alot of work (to optimize the sql joins)
p
Hi @Felix! I didn’t make much progress with .NET version. The idea I finished on is like this: - have regular prisma setup and autogenerated schema
- implement this schema completely in .net using graphqldotnet
f
right
why not make it directly in graphqldotnet ?
p
- for every resolver proxy requests/responses from own resolvers to prisma and back
this is to utilize prisma’s features for SQL generation first of all
f
can you use the filtering querying features of prisma this way ?
and sorting/paging etc
p
but this looked too cumbersome so I simply moved my API completely to node.js… another kind of an overhead but I found it more appropriate in my case
f
right
but now you can't use .NET at all..
i know prisma is more optimized with the sql joins and all
p
Like I said, I haven’t implemented this in code so I can’t really tell whether it will work or not. But looking at how things are in Prisma I believe that it should
f
but i want to have the power of c#.net
but you moved completely to prisma and node now.. no .NET anymore ?
p
Another way might be to utilize microservices approach and have data access layer purely in prisma / node.js and the rest of service in dotnet
f
yes
p
on this project I am working on now - no .NET anymore. 😞
f
prisma closes to the client as 1 endpoint
ow bummer 🙂
and .NET as lambda's or azure functions
that's a good idea, i'll maybe do that
i also just fear it's more work as keeping another layer and schema intact
and check that all types are same
maybe i'll do all in graphqldotnet and use the dataloader where needed
at start you don't have much users anyway
i hope graphqldotnet is here to stay though
p
moving it entirely to node allowed me to run a complete data access layer with access control, validation and semi-custom resolvers for certain objects in less than 500 LOC and it works just fine.
f
or MS comes with some official library for .NET
p
if i’d go .NET way i would have to write who know how much code just to link graphql api and prisma…
f
or just not use prisma...
how many tables you have ?
it depends if the schema is big of course
p
nearly 50
f
ok that's indeed lots of work
for sure if optimization in joins is needed
for me it's for new projects
where at start table count is small
p
then it may be simpler to have your own .NET interface to prisma
f
now i just make the stuff in graphcool for quick testing
and then will port it to .NET when stuff gets stable
the reverse you mean ?
.NET against the client
and prisma queried by .NET ?
lol lots of approaches possible
p
to connect your graphqldotnet powered API with prisma backend and proxy requests/responses in and out
yeah it all about making choices 🙂
f
yea the right choice 🙂
just checking this now again: https://hasura.io
dunno if they have a .NET sdk or sth
p
what is actually missing and would help a lot to marry prisma and dotnet is a client code generator for .NET / C#.
like the one prisma has for TypeScript, same stuff but for C#. Then it would have been much easier to use it with .net
f
indeed
i'm also waiting on it since long
the .NET connector
they have lots of people asking for it in the issues
but not clear if this ever going to come
p
thanks for the link to hasura. looks interesting, will check it out
have you tried it?
f
no
but the hooks seem interesting also
postgress triggers
p
never really worked with postgres on any serious projects
f
its probably almost the same as sql server
i also prefer sql server
postgres is powerful though
p
perhaps now is the time for me to try it 🙂
f
but in prisma you are using it with mysql ? could also use prisma and another .NET graphql endpoint and then use federation to make 1 endpoint https://www.apollographql.com/docs/apollo-server/federation/introduction/