From faf13916ed6fce4bb234f4df3caf227c9abdc900 Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Thu, 3 Dec 2020 22:05:48 +0100 Subject: [PATCH] Fix getTypeInformationFromGQLSchema --- src/app/services/schema.service.ts | 14 ++++-- src/generated/graphql.schema.json | 76 +++++++++++------------------- src/generated/graphql.ts | 24 +++++----- 3 files changed, 50 insertions(+), 64 deletions(-) diff --git a/src/app/services/schema.service.ts b/src/app/services/schema.service.ts index 82d9159..33a6af3 100644 --- a/src/app/services/schema.service.ts +++ b/src/app/services/schema.service.ts @@ -6,7 +6,7 @@ import jsonSchema from 'src/generated/graphql.schema.json'; }) export class SchemaService { /** expects startingObject and variablePath and returns its type e.g. cargoBike, security.name -> returns the type of the name variable */ - getPropertyTypeFromSchema( + /*getPropertyTypeFromSchema( startingObjectName: string, variable: string ): string { @@ -38,7 +38,7 @@ export class SchemaService { variablePath.slice(1).join('.') ); } - } + }*/ getEnumValuesFromSchema(typeName: string): string[] { const types = jsonSchema.__schema.types; @@ -67,7 +67,7 @@ export class SchemaService { if (!field) { return { isPartOfType: false, type: '', isRequired: false }; } - const type = field.type.name || field.type.ofType.name; + const type = this.getTypeNameFromTypeObject(field.type); if (variablePath.length === 1) { const isRequired = field.type.kind === 'NON_NULL'; if ( @@ -94,6 +94,14 @@ export class SchemaService { } } + private getTypeNameFromTypeObject(typeObject: any) { + let object =typeObject; + while (object.name == null && object.ofType != null) { + object = object.ofType; + } + return object.name; + } + filterObject(graphQLTypeName: string, object: object): any { let filteredObject; if (Array.isArray(object)) { diff --git a/src/generated/graphql.schema.json b/src/generated/graphql.schema.json index ead9c42..d09e75b 100644 --- a/src/generated/graphql.schema.json +++ b/src/generated/graphql.schema.json @@ -75,9 +75,13 @@ "description": "see column A in info tabelle", "args": [], "type": { - "kind": "ENUM", - "name": "Group", - "ofType": null + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "Group", + "ofType": null + } }, "isDeprecated": false, "deprecationReason": null @@ -2374,33 +2378,21 @@ "deprecationReason": null }, { - "name": "start", + "name": "dateRange", "description": null, "args": [], "type": { "kind": "NON_NULL", "name": null, "ofType": { - "kind": "SCALAR", - "name": "Date", + "kind": "OBJECT", + "name": "DateRange", "ofType": null } }, "isDeprecated": false, "deprecationReason": null }, - { - "name": "end", - "description": null, - "args": [], - "type": { - "kind": "SCALAR", - "name": "Date", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "contactInformation", "description": null, @@ -2610,22 +2602,16 @@ "fields": null, "inputFields": [ { - "name": "start", + "name": "dateRange", "description": "if not set, CURRENT_DATE will be used", "type": { - "kind": "SCALAR", - "name": "Date", - "ofType": null - }, - "defaultValue": null - }, - { - "name": "end", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Date", - "ofType": null + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "DateRangeInput", + "ofType": null + } }, "defaultValue": null }, @@ -2745,21 +2731,11 @@ "defaultValue": null }, { - "name": "start", - "description": "if not set, CURRENT_DATE will be used", - "type": { - "kind": "SCALAR", - "name": "Date", - "ofType": null - }, - "defaultValue": null - }, - { - "name": "end", + "name": "dateRange", "description": null, "type": { - "kind": "SCALAR", - "name": "Date", + "kind": "INPUT_OBJECT", + "name": "DateRangeInput", "ofType": null }, "defaultValue": null @@ -3769,9 +3745,13 @@ "name": "dateRange", "description": null, "type": { - "kind": "INPUT_OBJECT", - "name": "DateRangeInput", - "ofType": null + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "DateRangeInput", + "ofType": null + } }, "defaultValue": null }, diff --git a/src/generated/graphql.ts b/src/generated/graphql.ts index bf95c5d..16ecf26 100644 --- a/src/generated/graphql.ts +++ b/src/generated/graphql.ts @@ -39,7 +39,7 @@ export type CargoBike = { __typename?: 'CargoBike'; id: Scalars['ID']; /** see column A in info tabelle */ - group?: Maybe; + group: Group; name: Scalars['String']; state?: Maybe; modelName?: Maybe; @@ -406,8 +406,7 @@ export enum Group { export type Participant = { __typename?: 'Participant'; id: Scalars['ID']; - start: Scalars['Date']; - end?: Maybe; + dateRange: DateRange; contactInformation: ContactInformation; usernamefLotte?: Maybe; usernameSlack?: Maybe; @@ -432,8 +431,7 @@ export type Participant = { export type ParticipantCreateInput = { /** if not set, CURRENT_DATE will be used */ - start?: Maybe; - end?: Maybe; + dateRange: DateRangeInput; /** must create contactinformation first, if you want to use new */ contactInformationId: Scalars['ID']; usernamefLotte?: Maybe; @@ -448,9 +446,7 @@ export type ParticipantCreateInput = { export type ParticipantUpdateInput = { id: Scalars['ID']; - /** if not set, CURRENT_DATE will be used */ - start?: Maybe; - end?: Maybe; + dateRange?: Maybe; /** must create contactinformation first, if you want to use new */ contactInformationId?: Maybe; usernamefLotte?: Maybe; @@ -562,7 +558,7 @@ export type Engagement = { export type EngagementCreateInput = { engagementTypeId: Scalars['ID']; - dateRange?: Maybe; + dateRange: DateRangeInput; participantId: Scalars['ID']; cargoBikeId: Scalars['ID']; }; @@ -2014,7 +2010,7 @@ export type DeleteEquipmentTypeMutation = { __typename?: 'Mutation', deleteEquip export type AddressFieldsFragment = { __typename?: 'Address', street: string, number: string, zip: string }; -export type CargoBikeFieldsForTableFragment = { __typename?: 'CargoBike', id: string, group?: Maybe, name: string, modelName?: Maybe, state?: Maybe, numberOfChildren?: Maybe, numberOfWheels?: Maybe, forCargo?: Maybe, forChildren?: Maybe, stickerBikeNameState?: Maybe, note?: Maybe, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe, insuranceData?: Maybe<{ __typename?: 'InsuranceData', billing?: Maybe, hasFixedRate?: Maybe, name?: Maybe, benefactor?: Maybe, noPnP?: Maybe, maintenanceResponsible?: Maybe, maintenanceBenefactor?: Maybe, maintenanceAgreement?: Maybe, fixedRate?: Maybe, projectAllowance?: Maybe, notes?: Maybe }>, dimensionsAndLoad?: Maybe<{ __typename?: 'DimensionsAndLoad', bikeLength?: Maybe, bikeWeight?: Maybe, bikeHeight?: Maybe, bikeWidth?: Maybe, hasCoverBox?: Maybe, lockable?: Maybe, maxWeightBox?: Maybe, maxWeightLuggageRack?: Maybe, maxWeightTotal?: Maybe, boxHeightRange?: Maybe<{ __typename?: 'NumRange', max?: Maybe, min?: Maybe }>, boxLengthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe, max?: Maybe }>, boxWidthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe, max?: Maybe }> }>, security?: Maybe<{ __typename?: 'Security', frameNumber?: Maybe, adfcCoding?: Maybe, keyNumberAXAChain?: Maybe, keyNumberFrameLock?: Maybe, policeCoding?: Maybe }>, technicalEquipment?: Maybe<{ __typename?: 'TechnicalEquipment', bicycleShift?: Maybe, isEBike?: Maybe, hasLightSystem?: Maybe, specialFeatures?: Maybe }>, taxes?: Maybe<{ __typename?: 'Taxes', costCenter?: Maybe, organisationArea?: Maybe }>, provider?: Maybe<( +export type CargoBikeFieldsForTableFragment = { __typename?: 'CargoBike', id: string, group: Group, name: string, modelName?: Maybe, state?: Maybe, numberOfChildren?: Maybe, numberOfWheels?: Maybe, forCargo?: Maybe, forChildren?: Maybe, stickerBikeNameState?: Maybe, note?: Maybe, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe, insuranceData?: Maybe<{ __typename?: 'InsuranceData', billing?: Maybe, hasFixedRate?: Maybe, name?: Maybe, benefactor?: Maybe, noPnP?: Maybe, maintenanceResponsible?: Maybe, maintenanceBenefactor?: Maybe, maintenanceAgreement?: Maybe, fixedRate?: Maybe, projectAllowance?: Maybe, notes?: Maybe }>, dimensionsAndLoad?: Maybe<{ __typename?: 'DimensionsAndLoad', bikeLength?: Maybe, bikeWeight?: Maybe, bikeHeight?: Maybe, bikeWidth?: Maybe, hasCoverBox?: Maybe, lockable?: Maybe, maxWeightBox?: Maybe, maxWeightLuggageRack?: Maybe, maxWeightTotal?: Maybe, boxHeightRange?: Maybe<{ __typename?: 'NumRange', max?: Maybe, min?: Maybe }>, boxLengthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe, max?: Maybe }>, boxWidthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe, max?: Maybe }> }>, security?: Maybe<{ __typename?: 'Security', frameNumber?: Maybe, adfcCoding?: Maybe, keyNumberAXAChain?: Maybe, keyNumberFrameLock?: Maybe, policeCoding?: Maybe }>, technicalEquipment?: Maybe<{ __typename?: 'TechnicalEquipment', bicycleShift?: Maybe, isEBike?: Maybe, hasLightSystem?: Maybe, specialFeatures?: Maybe }>, taxes?: Maybe<{ __typename?: 'Taxes', costCenter?: Maybe, organisationArea?: Maybe }>, provider?: Maybe<( { __typename?: 'Provider' } & ProviderFieldsGeneralFragment )>, lendingStation?: Maybe<( @@ -2116,7 +2112,7 @@ export type OrganisationFieldsGeneralFragment = { __typename?: 'Organisation', i & AddressFieldsFragment )> }; -export type ParticipantFieldsForBikePageFragment = { __typename?: 'Participant', id: string, start: any, end?: Maybe, usernamefLotte?: Maybe, usernameSlack?: Maybe, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe, contactInformation: ( +export type ParticipantFieldsForBikePageFragment = { __typename?: 'Participant', id: string, usernamefLotte?: Maybe, usernameSlack?: Maybe, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe, lockedUntil?: Maybe, dateRange: { __typename?: 'DateRange', from: any, to?: Maybe }, contactInformation: ( { __typename?: 'ContactInformation' } & ContactInformationFieldsGeneralFragment ) }; @@ -2457,8 +2453,10 @@ export const ContactInformationFieldsGeneralFragmentDoc = gql` export const ParticipantFieldsForBikePageFragmentDoc = gql` fragment ParticipantFieldsForBikePage on Participant { id - start - end + dateRange { + from + to + } usernamefLotte usernameSlack contactInformation {