Feat/front forge graphql query (#2007)
* wip * Wip * Wip * Finished v1 * Wip * Fix from PR * Removed unused fragment masking feature * Fix from PR * Removed POC from nav bar * Fix lint --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
// TODO: add zod to validate that we have at least id on each object
|
||||
export const useCreateOneCustomObject = ({
|
||||
_objectName,
|
||||
}: {
|
||||
_objectName: string;
|
||||
}) => {
|
||||
// TODO : code
|
||||
};
|
||||
59
front/src/modules/metadata/hooks/useFindManyCustomObjects.ts
Normal file
59
front/src/modules/metadata/hooks/useFindManyCustomObjects.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { metadataObjectsState } from '../states/metadataObjectsState';
|
||||
import { generateFindManyCustomObjectsQuery } from '../utils/generateFindManyCustomObjectsQuery';
|
||||
|
||||
// TODO: add zod to validate that we have at least id on each object
|
||||
export const useFindManyCustomObjects = ({
|
||||
objectName,
|
||||
}: {
|
||||
objectName: string;
|
||||
}) => {
|
||||
const [metadataObjects] = useRecoilState(metadataObjectsState);
|
||||
|
||||
const foundObject = metadataObjects.find(
|
||||
(object) => object.nameSingular === objectName,
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({ foundObject });
|
||||
|
||||
const generatedQuery = foundObject
|
||||
? generateFindManyCustomObjectsQuery({
|
||||
metadataObject: foundObject,
|
||||
})
|
||||
: gql`
|
||||
query EmptyQuery {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
|
||||
const {
|
||||
fetchMore: fetchMoreBase,
|
||||
data,
|
||||
loading,
|
||||
error,
|
||||
} = useQuery(generatedQuery, {
|
||||
skip: !foundObject,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({ data, loading, error });
|
||||
|
||||
const fetchMore = ({ fromCursor }: { fromCursor: string }) => {
|
||||
fetchMoreBase({
|
||||
variables: { fromCursor },
|
||||
});
|
||||
};
|
||||
|
||||
const objectNotFoundInMetadata = metadataObjects.length > 0 && !foundObject;
|
||||
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
error,
|
||||
fetchMore,
|
||||
objectNotFoundInMetadata,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user