Fix getTypeInformationFromGQLSchema

pull/8/head
Max Ehrlicher-Schmidt 4 years ago
parent 968d5e70db
commit faf13916ed

@ -6,7 +6,7 @@ import jsonSchema from 'src/generated/graphql.schema.json';
}) })
export class SchemaService { export class SchemaService {
/** expects startingObject and variablePath and returns its type e.g. cargoBike, security.name -> returns the type of the name variable */ /** expects startingObject and variablePath and returns its type e.g. cargoBike, security.name -> returns the type of the name variable */
getPropertyTypeFromSchema( /*getPropertyTypeFromSchema(
startingObjectName: string, startingObjectName: string,
variable: string variable: string
): string { ): string {
@ -38,7 +38,7 @@ export class SchemaService {
variablePath.slice(1).join('.') variablePath.slice(1).join('.')
); );
} }
} }*/
getEnumValuesFromSchema(typeName: string): string[] { getEnumValuesFromSchema(typeName: string): string[] {
const types = jsonSchema.__schema.types; const types = jsonSchema.__schema.types;
@ -67,7 +67,7 @@ export class SchemaService {
if (!field) { if (!field) {
return { isPartOfType: false, type: '', isRequired: false }; 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) { if (variablePath.length === 1) {
const isRequired = field.type.kind === 'NON_NULL'; const isRequired = field.type.kind === 'NON_NULL';
if ( 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 { filterObject(graphQLTypeName: string, object: object): any {
let filteredObject; let filteredObject;
if (Array.isArray(object)) { if (Array.isArray(object)) {

@ -75,9 +75,13 @@
"description": "see column A in info tabelle", "description": "see column A in info tabelle",
"args": [], "args": [],
"type": { "type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM", "kind": "ENUM",
"name": "Group", "name": "Group",
"ofType": null "ofType": null
}
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
@ -2374,33 +2378,21 @@
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "start", "name": "dateRange",
"description": null, "description": null,
"args": [], "args": [],
"type": { "type": {
"kind": "NON_NULL", "kind": "NON_NULL",
"name": null, "name": null,
"ofType": { "ofType": {
"kind": "SCALAR", "kind": "OBJECT",
"name": "Date", "name": "DateRange",
"ofType": null "ofType": null
} }
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "end",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "Date",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "contactInformation", "name": "contactInformation",
"description": null, "description": null,
@ -2610,22 +2602,16 @@
"fields": null, "fields": null,
"inputFields": [ "inputFields": [
{ {
"name": "start", "name": "dateRange",
"description": "if not set, CURRENT_DATE will be used", "description": "if not set, CURRENT_DATE will be used",
"type": { "type": {
"kind": "SCALAR", "kind": "NON_NULL",
"name": "Date", "name": null,
"ofType": null "ofType": {
}, "kind": "INPUT_OBJECT",
"defaultValue": null "name": "DateRangeInput",
},
{
"name": "end",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Date",
"ofType": null "ofType": null
}
}, },
"defaultValue": null "defaultValue": null
}, },
@ -2745,21 +2731,11 @@
"defaultValue": null "defaultValue": null
}, },
{ {
"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, "description": null,
"type": { "type": {
"kind": "SCALAR", "kind": "INPUT_OBJECT",
"name": "Date", "name": "DateRangeInput",
"ofType": null "ofType": null
}, },
"defaultValue": null "defaultValue": null
@ -3769,9 +3745,13 @@
"name": "dateRange", "name": "dateRange",
"description": null, "description": null,
"type": { "type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT", "kind": "INPUT_OBJECT",
"name": "DateRangeInput", "name": "DateRangeInput",
"ofType": null "ofType": null
}
}, },
"defaultValue": null "defaultValue": null
}, },

@ -39,7 +39,7 @@ export type CargoBike = {
__typename?: 'CargoBike'; __typename?: 'CargoBike';
id: Scalars['ID']; id: Scalars['ID'];
/** see column A in info tabelle */ /** see column A in info tabelle */
group?: Maybe<Group>; group: Group;
name: Scalars['String']; name: Scalars['String'];
state?: Maybe<BikeState>; state?: Maybe<BikeState>;
modelName?: Maybe<Scalars['String']>; modelName?: Maybe<Scalars['String']>;
@ -406,8 +406,7 @@ export enum Group {
export type Participant = { export type Participant = {
__typename?: 'Participant'; __typename?: 'Participant';
id: Scalars['ID']; id: Scalars['ID'];
start: Scalars['Date']; dateRange: DateRange;
end?: Maybe<Scalars['Date']>;
contactInformation: ContactInformation; contactInformation: ContactInformation;
usernamefLotte?: Maybe<Scalars['String']>; usernamefLotte?: Maybe<Scalars['String']>;
usernameSlack?: Maybe<Scalars['String']>; usernameSlack?: Maybe<Scalars['String']>;
@ -432,8 +431,7 @@ export type Participant = {
export type ParticipantCreateInput = { export type ParticipantCreateInput = {
/** if not set, CURRENT_DATE will be used */ /** if not set, CURRENT_DATE will be used */
start?: Maybe<Scalars['Date']>; dateRange: DateRangeInput;
end?: Maybe<Scalars['Date']>;
/** must create contactinformation first, if you want to use new */ /** must create contactinformation first, if you want to use new */
contactInformationId: Scalars['ID']; contactInformationId: Scalars['ID'];
usernamefLotte?: Maybe<Scalars['String']>; usernamefLotte?: Maybe<Scalars['String']>;
@ -448,9 +446,7 @@ export type ParticipantCreateInput = {
export type ParticipantUpdateInput = { export type ParticipantUpdateInput = {
id: Scalars['ID']; id: Scalars['ID'];
/** if not set, CURRENT_DATE will be used */ dateRange?: Maybe<DateRangeInput>;
start?: Maybe<Scalars['Date']>;
end?: Maybe<Scalars['Date']>;
/** must create contactinformation first, if you want to use new */ /** must create contactinformation first, if you want to use new */
contactInformationId?: Maybe<Scalars['ID']>; contactInformationId?: Maybe<Scalars['ID']>;
usernamefLotte?: Maybe<Scalars['String']>; usernamefLotte?: Maybe<Scalars['String']>;
@ -562,7 +558,7 @@ export type Engagement = {
export type EngagementCreateInput = { export type EngagementCreateInput = {
engagementTypeId: Scalars['ID']; engagementTypeId: Scalars['ID'];
dateRange?: Maybe<DateRangeInput>; dateRange: DateRangeInput;
participantId: Scalars['ID']; participantId: Scalars['ID'];
cargoBikeId: 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 AddressFieldsFragment = { __typename?: 'Address', street: string, number: string, zip: string };
export type CargoBikeFieldsForTableFragment = { __typename?: 'CargoBike', id: string, group?: Maybe<Group>, name: string, modelName?: Maybe<string>, state?: Maybe<BikeState>, numberOfChildren?: Maybe<number>, numberOfWheels?: Maybe<number>, forCargo?: Maybe<boolean>, forChildren?: Maybe<boolean>, stickerBikeNameState?: Maybe<StickerBikeNameState>, note?: Maybe<string>, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe<string>, lockedUntil?: Maybe<any>, insuranceData?: Maybe<{ __typename?: 'InsuranceData', billing?: Maybe<string>, hasFixedRate?: Maybe<boolean>, name?: Maybe<string>, benefactor?: Maybe<string>, noPnP?: Maybe<string>, maintenanceResponsible?: Maybe<string>, maintenanceBenefactor?: Maybe<string>, maintenanceAgreement?: Maybe<string>, fixedRate?: Maybe<number>, projectAllowance?: Maybe<any>, notes?: Maybe<string> }>, dimensionsAndLoad?: Maybe<{ __typename?: 'DimensionsAndLoad', bikeLength?: Maybe<number>, bikeWeight?: Maybe<number>, bikeHeight?: Maybe<number>, bikeWidth?: Maybe<number>, hasCoverBox?: Maybe<boolean>, lockable?: Maybe<boolean>, maxWeightBox?: Maybe<number>, maxWeightLuggageRack?: Maybe<number>, maxWeightTotal?: Maybe<number>, boxHeightRange?: Maybe<{ __typename?: 'NumRange', max?: Maybe<number>, min?: Maybe<number> }>, boxLengthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe<number>, max?: Maybe<number> }>, boxWidthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe<number>, max?: Maybe<number> }> }>, security?: Maybe<{ __typename?: 'Security', frameNumber?: Maybe<string>, adfcCoding?: Maybe<string>, keyNumberAXAChain?: Maybe<string>, keyNumberFrameLock?: Maybe<string>, policeCoding?: Maybe<string> }>, technicalEquipment?: Maybe<{ __typename?: 'TechnicalEquipment', bicycleShift?: Maybe<string>, isEBike?: Maybe<boolean>, hasLightSystem?: Maybe<boolean>, specialFeatures?: Maybe<string> }>, taxes?: Maybe<{ __typename?: 'Taxes', costCenter?: Maybe<string>, organisationArea?: Maybe<OrganisationArea> }>, provider?: Maybe<( export type CargoBikeFieldsForTableFragment = { __typename?: 'CargoBike', id: string, group: Group, name: string, modelName?: Maybe<string>, state?: Maybe<BikeState>, numberOfChildren?: Maybe<number>, numberOfWheels?: Maybe<number>, forCargo?: Maybe<boolean>, forChildren?: Maybe<boolean>, stickerBikeNameState?: Maybe<StickerBikeNameState>, note?: Maybe<string>, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe<string>, lockedUntil?: Maybe<any>, insuranceData?: Maybe<{ __typename?: 'InsuranceData', billing?: Maybe<string>, hasFixedRate?: Maybe<boolean>, name?: Maybe<string>, benefactor?: Maybe<string>, noPnP?: Maybe<string>, maintenanceResponsible?: Maybe<string>, maintenanceBenefactor?: Maybe<string>, maintenanceAgreement?: Maybe<string>, fixedRate?: Maybe<number>, projectAllowance?: Maybe<any>, notes?: Maybe<string> }>, dimensionsAndLoad?: Maybe<{ __typename?: 'DimensionsAndLoad', bikeLength?: Maybe<number>, bikeWeight?: Maybe<number>, bikeHeight?: Maybe<number>, bikeWidth?: Maybe<number>, hasCoverBox?: Maybe<boolean>, lockable?: Maybe<boolean>, maxWeightBox?: Maybe<number>, maxWeightLuggageRack?: Maybe<number>, maxWeightTotal?: Maybe<number>, boxHeightRange?: Maybe<{ __typename?: 'NumRange', max?: Maybe<number>, min?: Maybe<number> }>, boxLengthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe<number>, max?: Maybe<number> }>, boxWidthRange?: Maybe<{ __typename?: 'NumRange', min?: Maybe<number>, max?: Maybe<number> }> }>, security?: Maybe<{ __typename?: 'Security', frameNumber?: Maybe<string>, adfcCoding?: Maybe<string>, keyNumberAXAChain?: Maybe<string>, keyNumberFrameLock?: Maybe<string>, policeCoding?: Maybe<string> }>, technicalEquipment?: Maybe<{ __typename?: 'TechnicalEquipment', bicycleShift?: Maybe<string>, isEBike?: Maybe<boolean>, hasLightSystem?: Maybe<boolean>, specialFeatures?: Maybe<string> }>, taxes?: Maybe<{ __typename?: 'Taxes', costCenter?: Maybe<string>, organisationArea?: Maybe<OrganisationArea> }>, provider?: Maybe<(
{ __typename?: 'Provider' } { __typename?: 'Provider' }
& ProviderFieldsGeneralFragment & ProviderFieldsGeneralFragment
)>, lendingStation?: Maybe<( )>, lendingStation?: Maybe<(
@ -2116,7 +2112,7 @@ export type OrganisationFieldsGeneralFragment = { __typename?: 'Organisation', i
& AddressFieldsFragment & AddressFieldsFragment
)> }; )> };
export type ParticipantFieldsForBikePageFragment = { __typename?: 'Participant', id: string, start: any, end?: Maybe<any>, usernamefLotte?: Maybe<string>, usernameSlack?: Maybe<string>, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe<string>, lockedUntil?: Maybe<any>, contactInformation: ( export type ParticipantFieldsForBikePageFragment = { __typename?: 'Participant', id: string, usernamefLotte?: Maybe<string>, usernameSlack?: Maybe<string>, isLocked: boolean, isLockedByMe: boolean, lockedBy?: Maybe<string>, lockedUntil?: Maybe<any>, dateRange: { __typename?: 'DateRange', from: any, to?: Maybe<any> }, contactInformation: (
{ __typename?: 'ContactInformation' } { __typename?: 'ContactInformation' }
& ContactInformationFieldsGeneralFragment & ContactInformationFieldsGeneralFragment
) }; ) };
@ -2457,8 +2453,10 @@ export const ContactInformationFieldsGeneralFragmentDoc = gql`
export const ParticipantFieldsForBikePageFragmentDoc = gql` export const ParticipantFieldsForBikePageFragmentDoc = gql`
fragment ParticipantFieldsForBikePage on Participant { fragment ParticipantFieldsForBikePage on Participant {
id id
start dateRange {
end from
to
}
usernamefLotte usernamefLotte
usernameSlack usernameSlack
contactInformation { contactInformation {

Loading…
Cancel
Save