Install ts-deep-extract-types

...to extract subtypes from generated GQL-result types
pull/1/head
Max Ehrlicher-Schmidt 4 years ago
parent 7d32b10740
commit c398e98cc2

5
package-lock.json generated

@ -14136,6 +14136,11 @@
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
"dev": true "dev": true
}, },
"ts-deep-extract-types": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ts-deep-extract-types/-/ts-deep-extract-types-1.0.1.tgz",
"integrity": "sha512-/ouif62vAoltKeN9tSxMkMfiFwrXttL5UHkGDDvshH3ml06t9HhTsrtVJneGJhojBlKbWs8qzHYhL7oGWuluUg=="
},
"ts-invariant": { "ts-invariant": {
"version": "0.4.4", "version": "0.4.4",
"resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.4.4.tgz", "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.4.4.tgz",

@ -28,6 +28,7 @@
"apollo-angular": "^2.0.4", "apollo-angular": "^2.0.4",
"graphql": "^15.3.0", "graphql": "^15.3.0",
"rxjs": "~6.5.5", "rxjs": "~6.5.5",
"ts-deep-extract-types": "^1.0.1",
"tslib": "^2.0.0", "tslib": "^2.0.0",
"zone.js": "~0.10.3" "zone.js": "~0.10.3"
}, },

@ -1,6 +1,7 @@
query CargoBikes { query GetCargoBikes{
cargoBikes { cargoBikes {
id id
group
name name
events { events {
date date
@ -12,5 +13,28 @@ query CargoBikes {
bikeLength bikeLength
bikeWeight bikeWeight
} }
numberOfChildren
security {
frameNumber
adfcCoding
keyNumberAXAChain
keyNumberFrameLock
policeCoding
}
dimensionsAndLoad {
bikeHeight
bikeLength
bikeWeight
bikeWidth
boxHeight
boxLength
boxWidth
hasCoverBox
lockable
maxWeightBox
maxWeightLuggageRack
maxWeightTotal
}
} }
} }

@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CargoBikesGQL, CargoBikesQuery, CargoBike } from '../../../generated/graphql'; import { DeepExtractTypeSkipArrays } from 'ts-deep-extract-types';
import { GetCargoBikesGQL, GetCargoBikesQuery } from '../../../generated/graphql';
type CargoBikeResult = DeepExtractTypeSkipArrays<GetCargoBikesQuery, ["cargoBikes"]>;
@Component({ @Component({
selector: 'app-bikes', selector: 'app-bikes',
@ -9,12 +12,12 @@ import { CargoBikesGQL, CargoBikesQuery, CargoBike } from '../../../generated/gr
export class BikesComponent implements OnInit { export class BikesComponent implements OnInit {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA; dataSource = ELEMENT_DATA;
bikes: CargoBikesQuery;
bikes: CargoBikeResult[];
constructor(private bikesGQL: CargoBikesGQL) { constructor(private bikesGQL: GetCargoBikesGQL) {
this.bikesGQL.watch().valueChanges.subscribe((result) => { this.bikesGQL.watch().valueChanges.subscribe((result) => {
console.log(result); this.bikes = result.data.cargoBikes;
this.bikes = result.data;
}); });
} }

@ -657,14 +657,14 @@ export enum CacheControlScope {
} }
export type CargoBikesQueryVariables = Exact<{ [key: string]: never; }>; export type GetCargoBikesQueryVariables = Exact<{ [key: string]: never; }>;
export type CargoBikesQuery = ( export type GetCargoBikesQuery = (
{ __typename?: 'Query' } { __typename?: 'Query' }
& { cargoBikes: Array<Maybe<( & { cargoBikes: Array<Maybe<(
{ __typename?: 'CargoBike' } { __typename?: 'CargoBike' }
& Pick<CargoBike, 'id' | 'name'> & Pick<CargoBike, 'id' | 'name' | 'numberOfChildren'>
& { events?: Maybe<Array<Maybe<( & { events?: Maybe<Array<Maybe<(
{ __typename?: 'BikeEvent' } { __typename?: 'BikeEvent' }
& Pick<BikeEvent, 'date'> & Pick<BikeEvent, 'date'>
@ -673,13 +673,16 @@ export type CargoBikesQuery = (
& Pick<InsuranceData, 'billing'> & Pick<InsuranceData, 'billing'>
), dimensionsAndLoad: ( ), dimensionsAndLoad: (
{ __typename?: 'DimensionsAndLoad' } { __typename?: 'DimensionsAndLoad' }
& Pick<DimensionsAndLoad, 'bikeLength' | 'bikeWeight'> & Pick<DimensionsAndLoad, 'bikeLength' | 'bikeWeight' | 'bikeHeight' | 'bikeWidth' | 'boxHeight' | 'boxLength' | 'boxWidth' | 'hasCoverBox' | 'lockable' | 'maxWeightBox' | 'maxWeightLuggageRack' | 'maxWeightTotal'>
), security: (
{ __typename?: 'Security' }
& Pick<Security, 'frameNumber'>
) } ) }
)>> } )>> }
); );
export const CargoBikesDocument = gql` export const GetCargoBikesDocument = gql`
query CargoBikes { query GetCargoBikes {
cargoBikes { cargoBikes {
id id
name name
@ -692,6 +695,34 @@ export const CargoBikesDocument = gql`
dimensionsAndLoad { dimensionsAndLoad {
bikeLength bikeLength
bikeWeight bikeWeight
bikeHeight
bikeWidth
boxHeight
boxLength
boxWidth
hasCoverBox
lockable
maxWeightBox
maxWeightLuggageRack
maxWeightTotal
}
numberOfChildren
security {
frameNumber
}
dimensionsAndLoad {
bikeHeight
bikeLength
bikeWeight
bikeWidth
boxHeight
boxLength
boxWidth
hasCoverBox
lockable
maxWeightBox
maxWeightLuggageRack
maxWeightTotal
} }
} }
} }
@ -700,8 +731,8 @@ export const CargoBikesDocument = gql`
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class CargoBikesGQL extends Apollo.Query<CargoBikesQuery, CargoBikesQueryVariables> { export class GetCargoBikesGQL extends Apollo.Query<GetCargoBikesQuery, GetCargoBikesQueryVariables> {
document = CargoBikesDocument; document = GetCargoBikesDocument;
constructor(apollo: Apollo.Apollo) { constructor(apollo: Apollo.Apollo) {
super(apollo); super(apollo);

Loading…
Cancel
Save