Mapping an array to an array and controlling the properties ?
See original GitHub issueHi,
I have successfully managed to do a standard mapping with some help from here, thank you.
So my destination object is like so, the keygroups property is actuall an Array of keyGroup.
export type KeyGroupPackage = {
keyGroups?: Maybe<Array<Maybe<KeyGroup>>>;
pageInfo?: Maybe<PageInfo>;
};
I have the paginfo working, its just doing standard property matching - so no problems there. ( i placed the code below) But I can’t get the array mapping to an array. My main schema that I run the morph
Here is my main command, to start the conversion.
morphism(keyGroupSchema, data)
export const packageSchema = createSchema<GraphQL.KeyGroupPackage, Responses.IKeyGroupRoot>({
keyGroups: morphism(keygroupSchema), /// THIS IS A PROBLEM.
pageInfo: morphism(paginationSchema)
})
The pageInfo works perfectly, I am placing the code below for the schema. But the keygroups does not. The keygroups is defined as an array on both source and destination.
I tried the following for the keygroup schema, which is defined above as morphism(keygroupSchema)
const keygroupSchema: StrictSchema<GraphQL.KeyGroup, Responses.IKeyGroup> = {
keyGroupId: "dddd"
}
The problem being is that both on the source and destination, the keygroups property is actually an array of keygroup.
An keygroup is like so
export type KeyGroup = { keyGroupId: string; name?: string; }
I was hoping to use the interatee like below, but its expecting an array - so it doesn’t work.
Pagination schema - works great 😃
const paginationSchema: StrictSchema<GraphQL.PageInfo, Responses.IKeyGroupRoot> = {
total: iteratee => iteratee.page.totalElements,
totalPages: iteratee => iteratee.page.totalPages,
page: iteratee => {
if (!isUndefined(iteratee.page.number)) {
return iteratee.page.number + 1
}
return 1
},
pageSize: iteratee => iteratee.page.size,
hasNextPage: iteratee => {
if (!isUndefined(iteratee.page.number) && !isUndefined(iteratee.page.totalPages)) {
return iteratee.page.number < iteratee.page.totalPages
}
return false
},
hasPreviousPage: iteratee => {
if (!isUndefined(iteratee.page.number)) {
return iteratee.page.number > 1
}
return false
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Can also be
Sure let me do it now ! And thanks for the support… Back in 10 😃