Skip to content

Commit

Permalink
feat: generate client-side query and mutations callsed generateClient…
Browse files Browse the repository at this point in the history
…SideDocuments

fix: bug in generating graphql client sie documents when type doesn't have required field
doc: added more comments
  • Loading branch information
Ostad authored and Ostad committed Apr 28, 2020
1 parent 6ba04e2 commit e06f5ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
17 changes: 10 additions & 7 deletions src/app.ts
Expand Up @@ -67,20 +67,23 @@ export async function main() {

// await generateInterfaceFiles({ objectAttributes, objectClasses });

// await generateGraphqlTypeFiles({
// objectClasses,
// objectAttributes,
// });

await generateGraphqlTypeFiles<StructuralClasses>({
await generateGraphqlTypeFiles({
objectClasses,
objectAttributes,
options: {
justThisClasses: ["user"],
generateClientSideDocuments: true,
},
});

// await generateGraphqlTypeFiles<StructuralClasses>({
// objectClasses,
// objectAttributes,
// options: {
// justThisClasses: ["user"],
// generateClientSideDocuments: true,
// },
// });

// await generateGraphqlTypeFiles<keyof typeof StructuralClassesEnum>({
// objectClasses,
// objectAttributes,
Expand Down
14 changes: 3 additions & 11 deletions src/helpers/map-class-attributes-include-inherited.ts
Expand Up @@ -12,24 +12,16 @@ type MapClassAttributesIncludeInheritedFnInput = {
/** all schema classes */
classes: Partial<SchemaClass>[];
options?: {
/** default true */
/** structural classes with objectClassCategory=1. default true */
justStructuralClasses?: boolean;
/** list of classes to generate classes
* - if not provided it generate all structural classes
* - if not provided it generate all structural classes (classes with objectClassCategory=1)
*/
justThisClasses?: string[];
};
};
/** @returns class attributes including inherited ones.
* @summary:
* 1. list auxiliary classes
* 2. list systemAuxiliary classes
* 3. create inheritance graph of structural classes with objectClassCategory=1 by following subClassOf field (class 'top' is parent of all classes)
* 4. get direct attributes of each class in graph
* 5. get direct attributes for class
* 6. merge direct attributes of class and override existing ones since direct attributes has more priority over attributes of auxiliary classes.
* - Note: child properties (override parent properties).
* if a field exist in parent and child, child's attributes should override parent's one. (Source: https://docs.oracle.com/cd/E23507_01/Platform.20073/RepositoryGuide/html/s1804itemdescriptorhierarchiesandinhe01.html)
* @note if a field exist in parent and child, child's attributes should override parent's one. (Source: https://docs.oracle.com/cd/E23507_01/Platform.20073/RepositoryGuide/html/s1804itemdescriptorhierarchiesandinhe01.html)
*/
export function mapClassAttributesIncludeInherited({
attributes,
Expand Down
55 changes: 28 additions & 27 deletions src/helpers/utils.ts
Expand Up @@ -84,13 +84,15 @@ type GetListOfParentsFnInput = {
/** ldapDisplayName of target class. this will use as first parent */
targetClassSubClassOf: LDAPDisplayName;
};
/** follow subClassOf field in class schema to gets to the top class

/** follow subClassOf field of schema class object to gets to the top class
* @returns array of ldapDisplayName
*/
export function getListOfParents({
allClasses,
targetClassSubClassOf,
}: GetListOfParentsFnInput): LDAPDisplayName[] {
writeLog(`getListOfParents()`, { level: "trace" });
/** placeholder for list of parents. */
const superClasses: LDAPDisplayName[] = [];

Expand Down Expand Up @@ -121,16 +123,18 @@ export function getListOfParents({
return superClasses.reverse();
}

type MergeAndOverrideAttributesFnInput = {
type MergeAttributesFnInput = {
/** keep these attributes in case same as extra attributes */
importantAttributes: AnalysedAttributeFields[];
/** these attributes will be overridden (less important to keep) in case same as extra attributes */
extraAttributes: AnalysedAttributeFields[];
};
/** Merge And Override Attributes */
export function mergeAttributes({
importantAttributes,
extraAttributes,
}: MergeAndOverrideAttributesFnInput): AnalysedAttributeFields[] {
}: MergeAttributesFnInput): AnalysedAttributeFields[] {
writeLog(`mergeAttributes()`, { level: "trace" });
/**
* - this is an object that each field represent one attribute.
* - this structure prevents us from having duplicate attribute and also makes override easier.
Expand All @@ -154,30 +158,6 @@ export function mergeAttributes({
return Object.values(mergedAttributes);
}

type MergeAttributesOfAuxiliaryClassesFnInput = {
classesWithAttributes: SchemaClassWithAttributes[];
targetClass: SchemaClassWithAttributes;
};
/** merge direct attributes with in auxiliaryClass and systemAuxiliaryClass fields to target class.
* @note :
* - it includes inherited attributes of parent classes
* - for auxiliary classes it ignores 'top' in parent classes to prevent processing it multiple times
* @note :
* - auxiliary classes can be subClassOf other auxiliary classes
* - auxiliary classes can have auxiliaryClass and systemAuxiliaryClass fields that reference to other auxiliary classes
* @plan for getting attributes of auxiliaryClass and systemAuxiliaryClass classes:
* 1. get direct Attributes of target class
* 2. get auxiliary classes of target class
* 2.1 process each auxiliary class
* 2.2 get direct attributes of that auxiliary class
*
*
* 4. merge it with attributes place holder named auxiliaryAttributes
* 5. get parent classes and filter-out 'top' and class name itself (some classes are subClassOf themselves!)
* 6. do the same steps above for parents classes recursively
* 7. merge auxiliaryAttributes with directAttributes (override directAttributes)
*/

type FindClassFnInput = {
classesWithAttributes: SchemaClassWithAttributes[];
ldapDisplayName: LDAPDisplayName;
Expand All @@ -186,6 +166,7 @@ export function findClass({
classesWithAttributes,
ldapDisplayName,
}: FindClassFnInput): SchemaClassWithAttributes {
writeLog(`findClass()`, { level: "trace" });
const classObj = classesWithAttributes.find(
(el) => el.lDAPDisplayName === ldapDisplayName,
);
Expand All @@ -195,10 +176,22 @@ export function findClass({
return classObj;
}

type MergeAttributesOfAuxiliaryClassesFnInput = {
classesWithAttributes: SchemaClassWithAttributes[];
targetClass: SchemaClassWithAttributes;
};

/** merge direct attributes of targetClass with attributes of auxiliaryClass & systemAuxiliaryClass classes
* @note:
* - // TODO at this point it does not follow auxiliaryClass & systemAuxiliaryClass attributes of other auxiliary classes. (auxiliary classes can have auxiliaryClass and systemAuxiliaryClass fields that reference to other auxiliary classes)
* - // TODO at this point it does not follow subClassOf field. (auxiliary classes can be subClassOf other auxiliary classes)
*/
function mergeAttributesOfAuxiliaryClasses({
targetClass,
classesWithAttributes,
}: MergeAttributesOfAuxiliaryClassesFnInput): AnalysedAttributeFields[] {
writeLog(`mergeAttributesOfAuxiliaryClasses()`, { level: "trace" });

/** placeholder for ldap name of all classes that this class gets its attributes from */
const attributeClasses: string[] = [];

Expand Down Expand Up @@ -235,10 +228,18 @@ type GetAllAttributesFnInput = {
classesWithAttributes: SchemaClassWithAttributes[];
targetClass: SchemaClassWithAttributes;
};
/** merge direct attributes with in auxiliaryClass and systemAuxiliaryClass fields to target class respecting inheritance.
* @note :
* - it includes inherited attributes of parent classes
* - auxiliary classes can be subClassOf other auxiliary classes
* - auxiliary classes can have auxiliaryClass and systemAuxiliaryClass fields that reference to other auxiliary classes.
*/
export function getAllAttributes({
targetClass,
classesWithAttributes,
}: GetAllAttributesFnInput): AnalysedAttributeFields[] {
writeLog(`getAllAttributes()`, { level: "trace" });

const directAttributes = mergeAttributesOfAuxiliaryClasses({
classesWithAttributes,
targetClass,
Expand Down

0 comments on commit e06f5ef

Please sign in to comment.