I'm trying to understand Spring Boot and building Rest APIs.
I've seen some projects which is creates their own Converter class or which is using modelMapper. But I couldn't clearly get the main idea.
Why do we have to convert entities to DTOs? I could'nt find a lot of docs about it. Can you help me?
I've found two different things for mapping.
mapstruct and modelmapper. Which one should i use?
DTO Represents Data Transfer Objects, They can be useful in many situation.
Since the entity represents the database and has all fields created directly eg. a product entity has following schema
name: "String",
desc: "string",
quantity_number: integer,
quantity_qom: "string",
amount_price: 200
amount_measure: "USD"
DTO helps us show response or request in a structured manner like
{ product:{
item:{
name:"string",
desc:"string",
},
amount:{
amount_price:200,
amount_measure:"USD"
},
quantity:{
quantity_number:2,
quantity_qom:"Pcs"
}
}
}
Regarding the usage i prefer modelmapper.
Related
I'm new to FHIR and need to implement a simple interface. So far I'm trying to understand from the documentation the basics but there are lots of new terms so simple question...
Patient/{ID}
In this case I return a resource type of Patient with the details of a patient. So far so good!
Patient?name.given=Joe&name.family=Blogs
The above would be the index method. However, in this case I can return multiple patients.
What "type" or structure do I use to simply return an indexed list of responses?
I've seen possible candidates as List, Group, Composition and Bundle.
I need to know this generally so I can return the correct type for all "index" methods in RESTful Fhir.
Use Bundle.
{
"resourceType:"Bundle",
"type": "searchset",
"entry":[...]
}
Check https://www.hl7.org/fhir/bundle.html and see what you need to implement based on your requirments. As you can see almost everything in FHIR is optional.
I've been looking around to see if a pattern exists for merging two graphQL datasets which contain the same type of data. What I mean is, given the following two type definitions;
type StevesBooks {
title: String
author: String
}
type DavesBooks {
title: String
author: String
}
If both of those are implemented as graphQL schemas separately/remotely, each with their own set of resolvers, is there a pattern or paradigm I can draw from to create a third graphQL instance that combines these two, so I can query "SteveAndDavesBooks" at the same time?
I found mergeSchemas in the apolloServer API but that solves a different problem to this one and all of the conflict-resolution methods in there require you to "choose a side" so to speak, rather than combine the results.
Is there already-written plugin or library somewhere that will help to achieve the above or do you think this is going to be something bespoke that I need to do myself?
I saw that query federation is on the roadmap - does anyone know any more details about that because that sounds like what I'm after.
Assume we have a model Book which contains another model Author.
Now lets send a query like:
query Book {
newestBooks(count: 200) {
id
title
author {
name
}
}
}
In my BookResolver I provide a method getAuthor() which is called once for each Book.
If the getAuthor() method loads the author from another service over the network or from the database a lot of overhead will occur for a large number of Books.
Is there a way in GraphQL to do some kind of a bulk request for populating the author field of the n Book instances?
I am evaluationg GraphQL with Java and Spring Boot, but I guess this topic is only concept and not environment related...
You are probably looking for the DataLoader concept. DataLoader ported to Java is available here.
I understand the principles of querying via graphql from the docs you could search:
{
"hero": {
"name": "R2-D2"
}
}
but how about you want to do something a bit more intricate such as:
{
"hero": {
"name": "R2-D2 AND C-3PO AND BB-8 NOT K-2SO"
}
}
is there any way to pass a string like this and get the appropriate results?
No, there isn't.
You can read through the GraphQL spec and see what it does and doesn't define. In particular the spec doesn't define any sort of filtering, any sort of expression language, or any sort of Boolean combinators. (There is no native way to say the equivalent of SQL's WHERE NAME='foo' without a field resolver explicitly adding it.)
What GraphQL allows for field arguments is sufficiently open-ended that you can build richer queries on top of it, but that's very specific to some application or library. Two prominent examples are the GitHub GraphQL API (which tends to allow exact-match queries on selected fields but nothing richer) and the Prisma API (which has an involved multi-level object scheme to replicate SQL queries).
I run a Java GraphQL server with Apollo client. My model is based on personas - each one can be an 'Actor', 'SoccerPlayer', 'Politician', etc.., all implement the 'Person' interface.
I have a 'Search' field, returning list of 'Person', however one entity might be of two types..
For example, when querying for
Search (text: "Ronald Reagan"){
id
name
... on Actor{
films{
name
}
}
... on Politician{
party{
name
}
}
}
I would expect to get both 'films' and 'party' for the former US president and actor, although typeResolver (on server side) forces me to return only one type. Is this doable at all with GraphQL? Maybe my model is wrong?
Thanks
GraphQL spec does not allow for multi-level inheritance, so with your specific structure, a Person can either be one or the other, but not both Actor and Politician.
You could get slightly closer to your goal if you turned Actor and Politician into interfaces themselves, but you'd have to repeat the fields from Person in each one as, again, no multi-level inheritance is possible.