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:
Lucas Bordeau
2023-10-13 22:27:57 +02:00
committed by GitHub
parent 3ef9132525
commit a35ea5e8f9
16 changed files with 406 additions and 2 deletions

View File

@ -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
};

View 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,
};
};