5

Which .NET GraphQL Clients Should Your App Use?

 2 years ago
source link: https://techcommunity.microsoft.com/t5/healthcare-and-life-sciences/which-net-graphql-clients-should-your-app-use/ba-p/3073261?WT_mc_id=DOP-MVP-4025064
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Which .NET GraphQL Clients Should Your App Use?

Which .NET GraphQL Clients Should Your App Use?

Published Jan 27 2022 08:43 AM 1,320 Views

Using a GraphQL API is a fantastic way to accelerate development.  But GraphQL was developed for JavaScript, a non-typed language.  .NET app developers can, and should, use GraphQL.   HotChocolate is an open source GraphQL library to make it easy to develop a GraphQL endpoint. 

But what should you use for developing a dotnet Client to a GraphQL API? 



Strawberry Shake

Strawberry Shake is an open-source automated code generation tool from the makers of HotChocolate.  Strawberry Shake generates a Client class using your API’s GraphQL schema and your project’s queries/mutations.  







The Strawberry Shake generated client is called by a Blazor app, translates those calls to GraphQL, and sends them on to the GraphQL endpoint. The instructions for setting this up are simple and will take less than 10 minutes. 



There are many advantages to Strawberry Shake.

Let’s look a bit deeper into the generated client to see the potential problems of using Strawberry Shake.  In some cases, Strawberry Shake will introduce unexpected hurdles.  Let’s look at a real example to see the hurdles and solutions.



Beyond The Basic App

My team was updating our FHIR Blaze app from REST to GraphQL.  FHIR Blaze is a sample Blazor app that works with HL7 FHIR APIs.  FHIR Blaze uses Firely to model the complex HL7 FHIR objects.  Our GraphQL provider for HL7 FHIR is Graphir.



Graphir’s GraphQL schema contains this section for getting a Patient:



















 Patient(id: String!): Patient!


















where the complex Patient type is defined as:



















type Practitioner {
  id: String
  identifier: [Identifier]
  active: Boolean
  name: [HumanName]
  language: String
  gender: AdministrativeGender
  birthDate: String
  telecom: [ContactPoint]
  address: [Address]
  photo: [Attachment]
  communication: [CodeableConcept]
  qualification: [QualificationComponent]
}


















Now let's say our app stores all its Patient Queries in Patient.GraphQL that looks like



















query getPatientID:Patient(id:"123"){
    id
  }

query getPatientIDGender:Patient(id:"123"){
    id gender
  }
}


















Strawberry Shake generates a 1,128 line Client for us. But there's a problem.

Calling Client.getPatientID("123"), we don't get back a Patient object.  Instead we get back a custom result object with an id field of type string.

Similarly Client.getPatientIDGender(123) returns a different custom object with two string fields: id and gender.



Our Blazor App has components that need an HL7 FHIR Patient object as input. We need a Patient object..

But don’t worry we have some solutions!



Custom GraphQL Request/Response

We can create custom GraphQL Request / Response objects. 

Example GraphQL Request Object.

Example GraphQL Response Object.

Now from our custom client we can generate a Request object with a GraphQL query.

















 public async Task<Patient> GetPatientAsync(string id)
        {
            GraphQLRequest request = new GraphQLRequest(_httpClient)
            {
                OperationName = "PatientList",
                Query = @"query getPatientID{
                     Patient(id:"123"){
                         id
                      }
               }"
            };
            GraphQLResponse response = await request.PostAsync();

            return _fhirParser.Parse<Patie(response.RootElement.ToString()));;
                
        }
















Now when we call getPatient("123") we get back a Patient object!



There are advantages to this approach:



There are also disadvantages:



Hybrid approach.

A final approach is to use Strawberry Shake to retrieve fields and then rehydrate complex objects with the contents.

For example:

















public Patient getPatient(string id){
  var psuedoPatient= Client.getPatient(id);
  string json=System.Text.JsonJsonSerializer.Serialize(psuedoPatient);
 return _fhirParser.Parse<Patient>());
}
















This might seem like the obvious solution, but this may not work for complex objects.  For example, a Patient object can have a Practitioner object embedded in it.  To rehydrate the Patient, you’d first have to rehydrate the embedded Practiioner object, and any complex objects under it.  An example we ran into during FHIR Blaze we cannot rehydrate a list of Patients directly, instead we need access to the underlying json.  You can see the code here.



What should I use?

If you’re developing an app and you have the code that represents the complex objects you’ll retrieve from your API: use custom coded classes.



Strawberry Shake also has other features that we did not cover here (including caching, support for subscriptions, etc). There are advantages and disadvantages of this approach.  You should use which ever approach increases your agility, after all that’s why you’re using GraphQL.



1 Comment

‎Jan 29 2022 12:00 AM

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

%3CLINGO-SUB%20id%3D%22lingo-sub-3073261%22%20slang%3D%22en-US%22%3EWhich%20.NET%20GraphQL%20Clients%20Should%20Your%20App%20Use%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3073261%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20a%20GraphQL%20API%20is%20a%20fantastic%20way%20to%20accelerate%20development.%26nbsp%3B%20But%20GraphQL%20was%20developed%20for%20JavaScript%2C%20a%20non-typed%20language.%20%26nbsp%3B.NET%20app%20developers%20can%2C%20and%20should%2C%20use%20GraphQL.%20%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fchillicream.com%2Fdocs%2Fhotchocolate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHotChocolate%3C%2FA%3E%20is%20an%20open%20source%20GraphQL%20library%20to%20make%20it%20easy%20to%20develop%20a%20GraphQL%20endpoint.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EBut%20what%20should%20you%20use%20for%20developing%20a%20dotnet%20Client%20to%20a%20GraphQL%20API%3F%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-2133419315%22%20id%3D%22toc-hId-2133541362%22%3EStrawberry%20Shake%3C%2FH1%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fchillicream.com%2Fdocs%2Fstrawberryshake%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EStrawberry%20Shake%3C%2FA%3E%20is%20an%20open-source%20automated%20code%20generation%20tool%20from%20the%20makers%20of%20HotChocolate.%26nbsp%3B%20Strawberry%20Shake%20generates%20a%20Client%20class%20using%20your%20API%E2%80%99s%20GraphQL%20schema%20and%20your%20project%E2%80%99s%20queries%2Fmutations.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22strawberryshake.png%22%20style%3D%22width%3A%20800px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F342965i9FFF0ADE0891801E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22strawberryshake.png%22%20alt%3D%22strawberryshake.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Strawberry%20Shake%20generated%20client%20is%20called%20by%20a%20Blazor%20app%2C%20translates%20those%20calls%20to%20GraphQL%2C%20and%20sends%20them%20on%20to%20the%20GraphQL%20endpoint.%20The%20%3CA%20href%3D%22https%3A%2F%2Fchillicream.com%2Fdocs%2Fstrawberryshake%2Fget-started%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Einstructions%3C%2FA%3E%20for%20setting%20this%20up%20are%20simple%20and%20will%20take%20less%20than%2010%20minutes.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20many%20advantages%20to%20Strawberry%20Shake.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EGraphQL%20queries%20and%20mutations%20are%20stored%20in%20.GraphQL%20files%20preserving%20their%20whitespace%20and%20isolating%20them%20away%20from%20C%23%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EThe%20generated%20client%20will%20update%20automatically%20with%20changes%20to%20your%20queries%2Fmutations.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ELet%E2%80%99s%20look%20a%20bit%20deeper%20into%20the%20generated%20client%20to%20see%20the%20potential%20problems%20of%20using%20Strawberry%20Shake.%26nbsp%3B%20In%20some%20cases%2C%20Strawberry%20Shake%20will%20introduce%20unexpected%20hurdles.%26nbsp%3B%20Let%E2%80%99s%20look%20at%20a%20real%20example%20to%20see%20the%20hurdles%20and%20solutions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-325964852%22%20id%3D%22toc-hId-326086899%22%3EBeyond%20The%20Basic%20App%3C%2FH1%3E%0A%3CP%3EMy%20team%20was%20updating%20our%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Ffhirblaze%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EFHIR%20Blaze%3C%2FA%3E%20app%20from%20REST%20to%20GraphQL.%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Ffhirblaze%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EFHIR%20Blaze%3C%2FA%3E%20is%20a%20sample%20Blazor%20app%20that%20works%20with%20%3CA%20href%3D%22https%3A%2F%2Fwww.hl7.org%2Ffhir%2Fquestionnaire-definitions.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHL7%20FHIR%3C%2FA%3E%20APIs.%20%26nbsp%3BFHIR%20Blaze%20uses%20%3CA%20href%3D%22https%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3Dfireley%2Bdotnet%26amp%3Bcvid%3D78c8b0cbe8ab47bbbf68202256c080e9%26amp%3Baqs%3Dedge..69i57j0j69i64.3518j0j9%26amp%3BFORM%3DANAB01%26amp%3BPC%3DU531%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EFirely%3C%2FA%3E%20to%20model%20the%20complex%20HL7%20FHIR%20objects.%26nbsp%3B%20Our%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fgraphir%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGraphQL%20provider%20for%20HL7%20FHIR%20is%20Graphir.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGraphir%E2%80%99s%20GraphQL%20schema%20contains%20this%20section%20for%20getting%20a%20Patient%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%20Patient(id%3A%20String!)%3A%20Patient!%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ewhere%20the%20complex%20Patient%20type%20is%20defined%20as%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3Etype%20Practitioner%20%7B%0A%20%20id%3A%20String%0A%20%20identifier%3A%20%5BIdentifier%5D%0A%20%20active%3A%20Boolean%0A%20%20name%3A%20%5BHumanName%5D%0A%20%20language%3A%20String%0A%20%20gender%3A%20AdministrativeGender%0A%20%20birthDate%3A%20String%0A%20%20telecom%3A%20%5BContactPoint%5D%0A%20%20address%3A%20%5BAddress%5D%0A%20%20photo%3A%20%5BAttachment%5D%0A%20%20communication%3A%20%5BCodeableConcept%5D%0A%20%20qualification%3A%20%5BQualificationComponent%5D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20let's%20say%20our%20app%20stores%20all%20its%20Patient%20Queries%20in%20Patient.GraphQL%20that%20looks%20like%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3Equery%20getPatientID%3APatient(id%3A%22123%22)%7B%0A%20%20%20%20id%0A%20%20%7D%0A%0Aquery%20getPatientIDGender%3APatient(id%3A%22123%22)%7B%0A%20%20%20%20id%20gender%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStrawberry%20Shake%20generates%20a%201%2C128%20line%20Client%20for%20us.%20But%20there's%20a%20problem.%3C%2FP%3E%0A%3CP%3ECalling%20Client.getPatientID(%22123%22)%2C%20we%20don't%20get%20back%20a%20Patient%20object.%26nbsp%3B%20Instead%20we%20get%20back%20a%20custom%20result%20object%20with%20an%20id%20field%20of%20type%20string.%3C%2FP%3E%0A%3CP%3ESimilarly%20Client.getPatientIDGender(123)%20returns%20a%20different%20custom%20object%20with%20two%20string%20fields%3A%20id%20and%20gender.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOur%20Blazor%20App%20has%20components%20that%20need%20an%20HL7%20FHIR%20Patient%20object%20as%20input.%20We%20need%20a%20Patient%20object..%3C%2FP%3E%0A%3CP%3EBut%20don%E2%80%99t%20worry%20we%20have%20some%20solutions!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--1481489611%22%20id%3D%22toc-hId--1481367564%22%3ECustom%20GraphQL%20Request%2FResponse%3C%2FH1%3E%0A%3CP%3EWe%20can%20create%20custom%20GraphQL%20Request%20%2F%20Response%20objects.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExample%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FFhirBlaze%2Fblob%2Fmain%2FFhirBlaze.SharedComponents%2FServices%2FGraphQL%2FRequest.cs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EGraphQL%20Request%3C%2FA%3E%20Object.%3C%2FP%3E%0A%3CP%3EExample%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FFhirBlaze%2Fblob%2Fmain%2FFhirBlaze.SharedComponents%2FServices%2FGraphQL%2FResponse.cs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EGraphQL%20Response%3C%2FA%3E%20Object.%3C%2FP%3E%0A%3CP%3ENow%20from%20our%20custom%20client%20we%20can%20generate%20a%20Request%20object%20with%20a%20GraphQL%20query.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3E%20public%20async%20Task%3CPATIENT%3E%20GetPatientAsync(string%20id)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20GraphQLRequest%20request%20%3D%20new%20GraphQLRequest(_httpClient)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20OperationName%20%3D%20%22PatientList%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Query%20%3D%20%40%22query%20getPatientID%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Patient(id%3A%22123%22)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20GraphQLResponse%20response%20%3D%20await%20request.PostAsync()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20_fhirParser.Parse%3CPATIE%3E%3C%2FPATIE%3E%3C%2FPATIENT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20when%20we%20call%20getPatient(%22123%22)%20we%20get%20back%20a%20Patient%20object!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20advantages%20to%20this%20approach%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EReuse%20the%20complex%20objects%20you%20already%20made.%20In%20our%20case%20we%E2%80%99re%20reusing%20the%20HL7%20FHIR%20objects%3C%2FLI%3E%0A%3CLI%3ENo%20reliance%20on%20black%20box%20code.%3C%2FLI%3E%0A%3CLI%3ESource%20tree%20is%20cleaner.%20Strawberry%20Shake%20is%20determensitic%2C%20but%20if%20you%20make%20a%20small%20change%20to%20your%20graphql%20queries%20you%20can%20expect%20hundreds%20of%20lines%20changed%20in%20the%20generated%20client.%26nbsp%3B%26nbsp%3B%20This%20will%20make%20diffs%20between%20versions%20giant.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20also%20disadvantages%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYou%20own%20the%20code%20you%20wrote.%20You%20now%20support%20it.%3C%2FLI%3E%0A%3CLI%3EGraphQL%20queries%20%2F%20mutations%20are%20sprinkled%20throughout%20your%20code.%20%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId-1006023222%22%20id%3D%22toc-hId-1006145269%22%3EHybrid%20approach.%3C%2FH1%3E%0A%3CP%3EA%20final%20approach%20is%20to%20use%20Strawberry%20Shake%20to%20retrieve%20fields%20and%20then%20rehydrate%20complex%20objects%20with%20the%20contents.%3C%2FP%3E%0A%3CP%3EFor%20example%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Epublic%20Patient%20getPatient(string%20id)%7B%0A%20%20var%20psuedoPatient%3D%20Client.getPatient(id)%3B%0A%20%20string%20json%3DSystem.Text.JsonJsonSerializer.Serialize(psuedoPatient)%3B%0A%20return%20_fhirParser.Parse%3CPATIENT%3E())%3B%0A%7D%0A%3C%2FPATIENT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20might%20seem%20like%20the%20obvious%20solution%2C%20but%20this%20may%20not%20work%20for%20complex%20objects.%26nbsp%3B%20For%20example%2C%20a%20Patient%20object%20can%20have%20a%20Practitioner%20object%20embedded%20in%20it.%20%26nbsp%3BTo%20rehydrate%20the%20Patient%2C%20you%E2%80%99d%20first%20have%20to%20rehydrate%20the%20embedded%20Practiioner%20object%2C%20and%20any%20complex%20objects%20under%20it.%20%26nbsp%3BAn%20example%20we%20ran%20into%20during%20FHIR%20Blaze%20we%20cannot%20rehydrate%20a%20list%20of%20Patients%20directly%2C%20instead%20we%20need%20access%20to%20the%20underlying%20json.%26nbsp%3B%20You%20can%20see%20the%20code%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FFhirBlaze%2Fblob%2Ffdf6bc12f6a61cce01ef77070a2450c9f53bb2dd%2FFhirBlaze.SharedComponents%2FServices%2FGraphirServices.cs%23L63%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH1%20id%3D%22toc-hId--801431241%22%20id%3D%22toc-hId--801309194%22%3EWhat%20should%20I%20use%3F%3C%2FH1%3E%0A%3CP%3EIf%20you%E2%80%99re%20developing%20an%20app%20and%20you%20have%20the%20code%20that%20represents%20the%20complex%20objects%20you%E2%80%99ll%20retrieve%20from%20your%20API%3A%20use%20custom%20coded%20classes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStrawberry%20Shake%20also%20has%20other%20features%20that%20we%20did%20not%20cover%20here%20(including%20caching%2C%20support%20for%20subscriptions%2C%20etc).%20There%20are%20advantages%20and%20disadvantages%20of%20this%20approach.%26nbsp%3B%20You%20should%20use%20which%20ever%20approach%20increases%20your%20agility%2C%20after%20all%20that%E2%80%99s%20why%20you%E2%80%99re%20using%20GraphQL.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3073261%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDeveloping%20a%20.NET%20app%20with%20a%20GraphQL%20backend%20you%E2%80%99re%20presented%20with%20a%20challenge%3A%20how%20will%20you%20make%20calls%20to%20the%20backend%20GraphQL%3F%20This%20article%20walks%20you%20through%20options%20with%20examples%2C%20and%20a%20workflow%20so%20that%20you%20can%20quickly%20make%20the%20choice%20and%20get%20to%20developing.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3073261%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHLS_Hack%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

Version history
Last update:

‎Jan 27 2022 09:11 AM

Updated by:
Labels

Share


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK