So aggregation is this thing where, for example, if I have three REST APIs and I have to get data that is related to all three, but I don't want to hit all three REST APIs. So that is where I can just aggregate them in one query and I can get back the answer.
So let's begin with this third section. As I said before, we have automatic schema generation. But you know, there are always edge cases or times that you want to have your own schema, so even that is supported. So if you notice, there is this configuration tab here. If you open this tab, you can go to this file that is called gql1-gql.yaml, and all this is already created here for you.
So we have two resolvers here. Both are REST resolvers. One will fetch the blocks for you, all the blocks will be fetched, and one will fetch the comments on these block posts. And you notice there is a block ID that is given here with parent.id. So if you notice here, we have this thing called comments. And now as you know, one block can have multiple comments, right? So we have a one-to-many relationship defined here, and this thing around this comment, this is called as a list. If you notice in this schema definition, there's a type block, okay? And you will notice here that the comments are in this list format, okay? And beside it, we have resolved it to get comments, which is defined here above, okay?
So if you highlight it, you will get to see that this is getting resolved from this rest API. Now what we have here is a one-to-many relationship, like one block can have many comments, right? So if you had a rest API, you would have to probably query the blocks first, okay? Then within that, you would have to get all the IDs from there, and then you would have to fire that to the comments to get all the answers, right? So in GraphQL, you just define the schema. You said that I want the ID, the user, the content title, and comments. And comment is a comment type. So within comments, you have these fields, it's ID, user, comments. So you can request GraphQL to, like, if you only want the comment ID, for example, or you want just a comment user who has commented this, you want to get the number of comments or something as such, right? And you also have a user type that has a user name, okay? So all that I'm explaining is also on the right-hand side, just in case it's a bit hard to understand anything, you can always refer to the side, to the right-hand side.
So once we have gone through this, in case anything is confusing, you can always post it in the comment box. I'm not sure if everyone is using the Q&A section. All right, so, and this is the query. So this is the type query that, this is your entry point basically. So we will apply this now. So you should get this thing that says GraphQL API created. Now if you do get GraphQL API, we should see a new blogs-graphql-defined. And if you notice, this is what we have sent basically to the GraphQL. So we have defined our own GraphQL API. Now that we have defined our GraphQL API, let's define the virtual service for it. So as I mentioned, all your virtual service is like an entry point, or if you want to think in terms of Apache, it's like a virtual host where you tell it what URL, what prefix, et cetera.
Comments