So what SOFA does, it takes the schema, it generates automatically REST calls that are kind of like the same as what we just talked about, what mesh does. And it looks at the types and generates the possible queries like the query beforehand, all the, like, let's say a query of all the different fields of a type and just generates like a RESTful API. So for each type, you get like a, you know, like you get basically an end point that queries all the different fields. So that does that automatically. Just one line of code and you get the REST API on top of your existing GraphQL API. The reason you want to do it is because, the reason we created it was we had, we were working with this big airline and the web parts of it moved into GraphQL, but the mobile parts thought like, yeah, GraphQL is just it's not interesting at all. But we still wanted to maintain one gateway. So we basically exposed REST for the mobile themes without them knowing that under the hood they're actually using GraphQL. And the coolest thing about it was when they wanted to customize, like one thing that happens when you, you were dealing with REST about these themes are coming, the front of the themes are coming and say, Hey, could you custom, could you change the endpoint or give me a new endpoint to give me a bit of this data and a bit of that data. So in what we did is we just re-created a new URL and attached a query to it. And that's it, you get a new custom endpoint. So, instead of now taking a whole week to create a new endpoint then now it just, it takes like five minutes. So that's what SOFA, it's basically the other way around, 13 GraphQL into REST. This game of like adjusting REST to all the different other sources is very interesting for us. Like we learned a lot about other protocols, like OData, which is super interesting protocol. So, JSON schema, like there's a lot of interesting protocols and playing with them really gives you like a different perspectives of what is possible and yeah, I hope it answers the question.
Cool. What are the caching capabilities of mesh? So I think I just answered to Liron's question. I shared the link also on the Medium. So you can look at it like there's basically you can, you can configure basically which fields, like you can configure the cache keys. You can invalidate it, you can use TTL, yeah, there's many, many different options there. There's a lot of options like I want, it will be cool if you could look at it and tell us if we like missed some capabilities or something in the caching that you might need. But basically the idea is that today, Meshed is also being used as a full fledged gateway with many of our clients, so it's needed to support all of it. So, again, in the beginning of the workshop, we just starting to use Meshed as an SDK, like as a better Apollo data source, but it also runs as a full fledged gateway, with all the caching capabilities. And actually, like, you can even define those caching stuff even if you generate an SDK, but yeah, hope that answers the question.
Again, we have, like, I think, even still like two hours to go through all those steps, so I want more questions. Like, if you- I have a question. Yeah. Okay, so I want to use a GraphQL Mesh, but the problem is like this. The services behind it, like I can have some REST API and some other GraphQLs and maybe a database. They all return the same schema. I need a discriminant on the client side, like let's say a tenant ID, and the logic will put me something like, if you have this tenant ID, I'll redirect you to the GraphQL one. If this is the tenant ID GraphQL two or REST three or directly to the database. So is this possible? How do I do this? Because I need exactly the same query and all of them have to have the exact same schema, but there are three services and each service is for a different tenant. I see. And the question is like, do you want to expose it to the client as a single schema or as kind of like schemas... Yes, no, no, no. I need one single schema, so the client doesn't need to know he's been redirected. It just something in his authentication or something behind the lines that says, oh, you're this tenant so you'll go there. It doesn't matter what you want or what you know, you'll never see the other ones. Yeah, yeah, yeah. So that's a really good question. First of all, the reason I ask if you want to expose them differently because many times there's conflicts between the different sources. And then the question is what to do. And everything is possible. It's just a question of what you prefer. So for example, what I shared was that you can use custom transforms and the transforms could do anything. So for example, you can prefix each one of those with something and then you have a... Even though there's conflicts, it's basically like namespaces or something like that. But that works for some use cases, but for your use case, that's not the case. But I'm just mentioning that it's possible for others. In your use case, what you want is basically you want something that runs like in front of all of those, kind of like a middleware or something that then redirects it to the right source. So there's few ways of doing it. I would suggest looking at like Resolver composition, like basically you can define some functions or it's kind of like a middleware that run in front of all of those. And like this run every time like before each Resolver is being called. And then you can run any arbitrary call there. So then you can basically write some code that takes from the context, basically the right let's say the right SDK or the right source and just pass the query to that source. So yeah, so that's definitely possible. If you need like more help with that, like I can even do like a reproduction or like an example, and I can go in and do some PRs if you couldn't figure it out but it's definitely possible.
Okay so, is this possible with GraphQL Mesh? Can I set it up with, what would I need to put in GraphQL Mesh to tell it to use this discriminant and just pick a source? So, what I imagine you are doing and I think you can start doing, if you can start doing it, let's say on GitHub and I can join and help you if you get stuck, is that I would first of all put in Mesh all those three sources. I will generate the schema and then I will use resolver composition to basically tell Mesh which SDK to use for each query. It's a bit complicated, it's not super straight forward, so actually it would be cool if you can have, I don't know if you can, if you have the option but you can create a simple reproduction, like a simple app that does something similar and then I can jump and help you to do that. Okay, thank you, I'll try to see if I can do some. Yeah, by the way, I'll share my GitHub so people, like in my Git, on my GitHub, there's also my private email. So if you want to contact me or you want to like, and of course you can always just like open an issue in GraphQL Meshes repo but yeah, I'm sharing just in case someone wants to. Okay, thank you. Yeah, welcome, more questions if you have. Okay, I'll give one more minute for people to ask and then we can actually start going through the steps. Again, you know, you could start doing those steps already, like just clone the repo and do that. I'll talk sharing, but please keep asking. Like I want you to keep asking questions. Like that's the whole, that's better for me. Okay, so what I have here. Okay, so what I have here is basically the first step, like if you clone the repo and then you check out this commit, this first commit, that's where I want you to be. Now and I want you to then, now clone it, check out these steps, then run the yarn to install all the stuff and run yarn start to run this thing. Now do it again. And just to go very quickly through the setup. And, again, if this is like, let's say you never run a GraphQL server before and you don't understand what's going on here, tell me, like, please stop me and please ask questions, there's no dumb questions at all here. So what I'm doing here is that I installed basically Apollo Server, which by the way, I'll just mention, I'm using Apollo Server here because it's the most popular option, but it's not the best option, in my opinion. So if you are using Node, let's say, and you want to build a GraphQL Server, you should look at, let me show you where... By the way, I'm going now to graphql.org. We kind of like rebuild graphql.org, we build it in Gatsby now, and we change the code sections. So now it's much more organized, and you can see it's organizing by languages, so if you go to JavaScript, we have the server implementation client libraries and tools. And we also ordered them by how popular they are and how well maintained they are, and stuff like that. So Apollo Server is one of the most popular options. But in my opinion, currently the best... But it's not well maintained, to be honest. The dependences are very old, and there's tons of issues, open issues there, and open PRs, and they're just not super active there. But in my opinion, the best option currently is this one, GraphQL Helix. I'll share the link with you, even though you can find it yourself.
Comments