graphql#IntrospectionObjectType TypeScript Examples
The following examples show how to use
graphql#IntrospectionObjectType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: getResponseParser.ts From ra-data-prisma with MIT License | 5 votes |
sanitizeResource =
(
introspectionResults: IntrospectionResult,
resource: Resource,
shouldSanitizeLinkedResources: boolean = true,
) =>
(data: { [key: string]: any } = {}): any => {
return Object.keys(data).reduce((acc, key) => {
if (key.startsWith("_")) {
return acc;
}
const field = (resource.type as IntrospectionObjectType).fields.find(
(f: any) => f.name === key,
)!;
const type = getFinalType(field.type);
if (type.kind !== TypeKind.OBJECT) {
return { ...acc, [field.name]: data[field.name] };
}
// FIXME: We might have to handle linked types which are not resources but will have to be careful about endless circular dependencies
const linkedResource = introspectionResults.resources.find(
(r) => r.type.name === type.name,
);
if (shouldSanitizeLinkedResources && linkedResource) {
const linkedResourceData = data[field.name];
if (Array.isArray(linkedResourceData)) {
return {
...acc,
[field.name]: data[field.name].map((obj) => obj.id),
};
}
return {
...acc,
[field.name]: data[field.name]?.id,
};
}
return { ...acc, [field.name]: data[field.name] };
}, {});
}