graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

How to use SendQueryAsync when the query returns multiple collections of results ?

Open AndreasDevDotNet opened this issue 3 years ago • 1 comments

I am new to GrahpQL and I am working on an integration project where our customer has a GraphQL API. I have a query that looks like this:

{
  maskiner {
    masktyp
    mnr
    kundnr
    avtalnr
    install
    plac
    gatuadr
    postnr
    ort
    land
    tel
    email
    portkod
    ref
    distrikt
    kategori
  }
  maskinty {
    artnr
    namn
  }
  mask3 {
    mnr
    projektnr_r1
  }
  projekt {
    nr
    namn
  }
}

this results in a json that contains 4 collections of data, I was expecting to get back json so that I could use the GetDataFieldAs method to just parse this out as 4 diffrent collections. But now I saw that that option has been removed and now I have to create a type that matches the result, how do I do that ?

/Andreas

AndreasDevDotNet avatar Apr 16 '21 12:04 AndreasDevDotNet

Well, create an object containing a property for each collection... something along the following:

public class ResponseObject {
    public List<MaskinerType> Maskiner { get; set; }
    public List<MaskintyType> Maskinty { get; set; }
    public List<Mask3Type> Mask3 { get; set; }
    public List<ProjectType> Project { get; set; }
}

rose-a avatar Apr 21 '21 19:04 rose-a