Friday, November 22, 2019

Map a GraphQL query to a specific type in an Angular application.

Instead of just a semicolon here we could have something like so:

.map(response => response.data.AnalyticsFacet as FacetsModel)

 
 

A example of what is handed in for a query might be:

let query = `{
      AnalyticsFacet(analyticsRequest:
      {
         domain: "${domain}",
         analysisType: "${analysisType}",
         filterList: ${filter},
         countStrategy: "documents"
      })
      {
         label
         facets {
            label
            count
            id
         }
      }
   }`;

 
 

So you may see how this stuff maps back here is our FacetsModel:

export interface FacetsModel {
   maxError?: number;
   label: string;
   rank?: number;
   facets: BaseFacetModel[];
}

 
 

BaseFacetModel is this this:

export interface BaseFacetModel {
   count: number;
   label:string;
   id: any;
   maxError?: number;
   facets?: BaseFacetModel[];
}

No comments:

Post a Comment