Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use generated document #709

Merged
merged 40 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8e8f1fe
feat: add graphql codegen
bigint Sep 30, 2022
e1fcaa2
feat: add more graphql document
bigint Sep 30, 2022
7f659f8
feat: add more graphql document
bigint Sep 30, 2022
144c596
feat: add more graphql document
bigint Sep 30, 2022
cae6f5e
feat: add more graphql document
bigint Sep 30, 2022
2058deb
feat: add more graphql document
bigint Sep 30, 2022
882ba50
feat: add more graphql document
bigint Sep 30, 2022
baea1eb
feat: add more graphql document
bigint Sep 30, 2022
4789768
feat: add more graphql document
bigint Sep 30, 2022
a6877b9
feat: add more graphql document
bigint Sep 30, 2022
cbc85ef
feat: add more graphql document
bigint Sep 30, 2022
0258e8e
feat: add more graphql document
bigint Sep 30, 2022
c91f903
fix: build
bigint Sep 30, 2022
db846be
feat: add more graphql document
bigint Oct 1, 2022
f9faa62
feat: add more graphql document
bigint Oct 1, 2022
cb7914c
feat: add more graphql document
bigint Oct 1, 2022
3d6583a
feat: add more graphql document
bigint Oct 1, 2022
c748db4
feat: add more graphql document
bigint Oct 1, 2022
b3c8c27
feat: add more graphql document
bigint Oct 1, 2022
1c81038
feat: add more graphql document
bigint Oct 1, 2022
26560ce
feat: add more graphql document
bigint Oct 1, 2022
3cbd029
feat: add more graphql document
bigint Oct 1, 2022
fc308ce
feat: add more graphql document
bigint Oct 1, 2022
87ecc3b
feat: add more graphql document
bigint Oct 1, 2022
dac0fad
feat: add more graphql document
bigint Oct 1, 2022
b4732fa
feat: add more graphql document
bigint Oct 1, 2022
fa98f3a
feat: add more graphql document
bigint Oct 1, 2022
9c78f82
feat: add more graphql document
bigint Oct 1, 2022
62ddc18
feat: add more graphql document
bigint Oct 1, 2022
8162f3a
feat: add more graphql document
bigint Oct 1, 2022
29a4bfc
feat: add more graphql document
bigint Oct 1, 2022
dd7e98f
feat: add more graphql document
bigint Oct 1, 2022
973a1b7
feat: add more graphql document
bigint Oct 1, 2022
87c9da7
feat: add more graphql document
bigint Oct 1, 2022
1eb3e02
fix: type errors
bigint Oct 1, 2022
8a091b6
fix: type errors
bigint Oct 1, 2022
ad13104
fix: type errors
bigint Oct 1, 2022
3d1bd6c
fix: type errors
bigint Oct 1, 2022
3e3034e
fix: type errors
bigint Oct 1, 2022
a5a408d
feat: add more graphql document
bigint Oct 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"unicorn/no-useless-undefined": "error",
"unicorn/prefer-array-find": "error"
},
"ignorePatterns": ["/src/generated/types.ts"]
"ignorePatterns": ["/src/generated/types.ts", "/src/generated/documents.ts"]
}
18 changes: 18 additions & 0 deletions codegen.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
schema: https://api-mumbai.lens.dev
documents:
[
'./src/graphql/queries/*.graphql',
'./src/graphql/mutations/*.graphql',
'./src/graphql/fragments/*.graphql'
]

hooks:
afterOneFileWrite:
Expand All @@ -10,3 +16,15 @@ generates:
plugins:
- typescript
- fragment-matcher
config:
fetcher: fetch
dedupeFragments: true

src/generated/documents.ts:
plugins:
- typescript
- typescript-operations
- typed-document-node
config:
fetcher: fetch
dedupeFragments: true
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"devDependencies": {
"@graphql-codegen/cli": "^2.13.1",
"@graphql-codegen/fragment-matcher": "^3.3.1",
"@graphql-codegen/typed-document-node": "^2.3.3",
"@graphql-codegen/typescript": "^2.7.3",
"@graphql-codegen/typescript-operations": "^2.5.3",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.2",
Expand Down
31 changes: 5 additions & 26 deletions src/components/Comment/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { gql, useQuery } from '@apollo/client';
import { useQuery } from '@apollo/client';
import QueuedPublication from '@components/Publication/QueuedPublication';
import SinglePublication from '@components/Publication/SinglePublication';
import PublicationsShimmer from '@components/Shared/Shimmer/PublicationsShimmer';
import { Card } from '@components/UI/Card';
import { EmptyState } from '@components/UI/EmptyState';
import { ErrorMessage } from '@components/UI/ErrorMessage';
import { Spinner } from '@components/UI/Spinner';
import { CommentFeedDocument } from '@generated/documents';
import { LensterPublication } from '@generated/lenstertypes';
import { CustomFiltersTypes } from '@generated/types';
import { CommentFields } from '@gql/CommentFields';
import { CollectionIcon } from '@heroicons/react/outline';
import { Mixpanel } from '@lib/mixpanel';
import React, { FC } from 'react';
Expand All @@ -21,27 +21,6 @@ import { PAGINATION } from 'src/tracking';
import CommentWarning from '../Shared/CommentWarning';
import NewComment from './New';

const COMMENT_FEED_QUERY = gql`
query CommentFeed(
$request: PublicationsQueryRequest!
$reactionRequest: ReactionFieldResolverRequest
$profileId: ProfileId
) {
publications(request: $request) {
items {
... on Comment {
...CommentFields
}
}
pageInfo {
totalCount
next
}
}
}
${CommentFields}
`;

interface Props {
publication: LensterPublication;
}
Expand All @@ -56,12 +35,12 @@ const Feed: FC<Props> = ({ publication }) => {
const reactionRequest = currentProfile ? { profileId: currentProfile?.id } : null;
const profileId = currentProfile?.id ?? null;

const { data, loading, error, fetchMore } = useQuery(COMMENT_FEED_QUERY, {
const { data, loading, error, fetchMore } = useQuery(CommentFeedDocument, {
variables: { request, reactionRequest, profileId },
skip: !publicationId
});

const comments = data?.publications?.items;
const comments = data?.publications?.items ?? [];
const pageInfo = data?.publications?.pageInfo;

const { observe } = useInView({
Expand Down Expand Up @@ -105,7 +84,7 @@ const Feed: FC<Props> = ({ publication }) => {
</div>
)
)}
{comments?.map((comment: LensterPublication, index: number) => (
{comments?.map((comment: any, index: number) => (
<SinglePublication key={`${publicationId}_${index}`} publication={comment} showType={false} />
))}
</Card>
Expand Down
13 changes: 6 additions & 7 deletions src/components/Comment/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ErrorMessage } from '@components/UI/ErrorMessage';
import { MentionTextArea } from '@components/UI/MentionTextArea';
import { Spinner } from '@components/UI/Spinner';
import useBroadcast from '@components/utils/hooks/useBroadcast';
import { CreateCommentTypedDataDocument, CreateCommentViaDispatcherDocument } from '@generated/documents';
import { LensterAttachment, LensterPublication } from '@generated/lenstertypes';
import {
CreateCommentBroadcastItemResult,
Expand All @@ -17,10 +18,6 @@ import {
ReferenceModules
} from '@generated/types';
import { IGif } from '@giphy/js-types';
import {
CREATE_COMMENT_TYPED_DATA_MUTATION,
CREATE_COMMENT_VIA_DISPATHCER_MUTATION
} from '@gql/TypedAndDispatcherData/CreateComment';
import { ChatAlt2Icon } from '@heroicons/react/outline';
import { defaultFeeData, defaultModuleData, getModule } from '@lib/getModule';
import getSignature from '@lib/getSignature';
Expand Down Expand Up @@ -127,7 +124,7 @@ const NewComment: FC<Props> = ({ hideCard = false, publication }) => {
}
});
const [createCommentTypedData, { loading: typedDataLoading }] = useMutation<Mutation>(
CREATE_COMMENT_TYPED_DATA_MUTATION,
CreateCommentTypedDataDocument,
{
onCompleted: async ({
createCommentTypedData
Expand Down Expand Up @@ -183,11 +180,13 @@ const NewComment: FC<Props> = ({ hideCard = false, publication }) => {
);

const [createCommentViaDispatcher, { loading: dispatcherLoading }] = useMutation(
CREATE_COMMENT_VIA_DISPATHCER_MUTATION,
CreateCommentViaDispatcherDocument,
{
onCompleted: (data) => {
onCompleted();
setTxnQueue([generateOptimisticComment(data?.createCommentViaDispatcher?.txHash), ...txnQueue]);
if (data.createCommentViaDispatcher.__typename === 'RelayerResult') {
setTxnQueue([generateOptimisticComment(data.createCommentViaDispatcher.txHash), ...txnQueue]);
}
},
onError
}
Expand Down
43 changes: 16 additions & 27 deletions src/components/Crowdfund/New.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LensHubProxy } from '@abis/LensHubProxy';
import { gql, useMutation, useQuery } from '@apollo/client';
import { useMutation, useQuery } from '@apollo/client';
import { GridItemEight, GridItemFour, GridLayout } from '@components/GridLayout';
import ChooseFile from '@components/Shared/ChooseFile';
import Pending from '@components/Shared/Pending';
Expand All @@ -13,11 +13,12 @@ import { Spinner } from '@components/UI/Spinner';
import { TextArea } from '@components/UI/TextArea';
import useBroadcast from '@components/utils/hooks/useBroadcast';
import Seo from '@components/utils/Seo';
import { CreatePostBroadcastItemResult, Erc20, Mutation, PublicationMainFocus } from '@generated/types';
import {
CREATE_POST_TYPED_DATA_MUTATION,
CREATE_POST_VIA_DISPATHCER_MUTATION
} from '@gql/TypedAndDispatcherData/CreatePost';
CreatePostTypedDataDocument,
CreatePostViaDispatcherDocument,
EnabledCurrencyModulesDocument
} from '@generated/documents';
import { CreatePostBroadcastItemResult, Erc20, Mutation, PublicationMainFocus } from '@generated/types';
import { PlusIcon } from '@heroicons/react/outline';
import getIPFSLink from '@lib/getIPFSLink';
import getSignature from '@lib/getSignature';
Expand Down Expand Up @@ -46,17 +47,6 @@ import { v4 as uuid } from 'uuid';
import { useContractWrite, useSignTypedData } from 'wagmi';
import { object, string } from 'zod';

const MODULES_CURRENCY_QUERY = gql`
query EnabledCurrencyModules {
enabledModuleCurrencies {
name
symbol
decimals
address
}
}
`;

const newCrowdfundSchema = object({
title: string()
.min(2, { message: 'Title should be atleast 2 characters' })
Expand Down Expand Up @@ -94,7 +84,7 @@ const NewCrowdfund: NextPage = () => {
};

const { isLoading: signLoading, signTypedDataAsync } = useSignTypedData({ onError });
const { data: currencyData, loading } = useQuery(MODULES_CURRENCY_QUERY);
const { data: currencyData, loading } = useQuery(EnabledCurrencyModulesDocument);

const {
data,
Expand Down Expand Up @@ -132,7 +122,7 @@ const NewCrowdfund: NextPage = () => {

const { broadcast, data: broadcastData, loading: broadcastLoading } = useBroadcast({ onCompleted });
const [createCrowdfundTypedData, { loading: typedDataLoading }] = useMutation<Mutation>(
CREATE_POST_TYPED_DATA_MUTATION,
CreatePostTypedDataDocument,
{
onCompleted: async ({
createPostTypedData
Expand Down Expand Up @@ -182,7 +172,7 @@ const NewCrowdfund: NextPage = () => {
);

const [createCrowdfundViaDispatcher, { data: dispatcherData, loading: dispatcherLoading }] = useMutation(
CREATE_POST_VIA_DISPATHCER_MUTATION,
CreatePostViaDispatcherDocument,
{ onCompleted, onError }
);

Expand Down Expand Up @@ -269,6 +259,11 @@ const NewCrowdfund: NextPage = () => {

const isLoading =
typedDataLoading || dispatcherLoading || isUploading || signLoading || writeLoading || broadcastLoading;
const txHash =
data?.hash ??
broadcastData?.broadcast?.txHash ??
(dispatcherData?.createPostViaDispatcher.__typename === 'RelayerResult' &&
dispatcherData?.createPostViaDispatcher.txHash);

return (
<GridLayout>
Expand All @@ -278,15 +273,9 @@ const NewCrowdfund: NextPage = () => {
</GridItemFour>
<GridItemEight>
<Card>
{data?.hash ??
broadcastData?.broadcast?.txHash ??
dispatcherData?.createPostViaDispatcher?.txHash ? (
{txHash ? (
<Pending
txHash={
data?.hash ??
broadcastData?.broadcast?.txHash ??
dispatcherData?.createPostViaDispatcher?.txHash
}
txHash={txHash}
indexing="Crowdfund creation in progress, please wait!"
indexed="Crowdfund created successfully"
type="crowdfund"
Expand Down
42 changes: 5 additions & 37 deletions src/components/Explore/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { gql, useQuery } from '@apollo/client';
import { useQuery } from '@apollo/client';
import SinglePublication from '@components/Publication/SinglePublication';
import PublicationsShimmer from '@components/Shared/Shimmer/PublicationsShimmer';
import { Card } from '@components/UI/Card';
import { EmptyState } from '@components/UI/EmptyState';
import { ErrorMessage } from '@components/UI/ErrorMessage';
import { Spinner } from '@components/UI/Spinner';
import { LensterPublication } from '@generated/lenstertypes';
import { ExploreFeedDocument } from '@generated/documents';
import { CustomFiltersTypes, PublicationSortCriteria } from '@generated/types';
import { CommentFields } from '@gql/CommentFields';
import { MirrorFields } from '@gql/MirrorFields';
import { PostFields } from '@gql/PostFields';
import { CollectionIcon } from '@heroicons/react/outline';
import { Mixpanel } from '@lib/mixpanel';
import React, { FC } from 'react';
Expand All @@ -18,37 +15,8 @@ import { PAGINATION_ROOT_MARGIN } from 'src/constants';
import { useAppStore } from 'src/store/app';
import { PAGINATION } from 'src/tracking';

export const EXPLORE_FEED_QUERY = gql`
query ExploreFeed(
$request: ExplorePublicationRequest!
$reactionRequest: ReactionFieldResolverRequest
$profileId: ProfileId
) {
explorePublications(request: $request) {
items {
... on Post {
...PostFields
}
... on Comment {
...CommentFields
}
... on Mirror {
...MirrorFields
}
}
pageInfo {
totalCount
next
}
}
}
${PostFields}
${CommentFields}
${MirrorFields}
`;

interface Props {
feedType?: string;
feedType?: PublicationSortCriteria;
}

const Feed: FC<Props> = ({ feedType = PublicationSortCriteria.CuratedProfiles }) => {
Expand All @@ -64,7 +32,7 @@ const Feed: FC<Props> = ({ feedType = PublicationSortCriteria.CuratedProfiles })
const reactionRequest = currentProfile ? { profileId: currentProfile?.id } : null;
const profileId = currentProfile?.id ?? null;

const { data, loading, error, fetchMore } = useQuery(EXPLORE_FEED_QUERY, {
const { data, loading, error, fetchMore } = useQuery(ExploreFeedDocument, {
variables: { request, reactionRequest, profileId }
});

Expand Down Expand Up @@ -98,7 +66,7 @@ const Feed: FC<Props> = ({ feedType = PublicationSortCriteria.CuratedProfiles })
{!error && !loading && publications?.length !== 0 && (
<>
<Card className="divide-y-[1px] dark:divide-gray-700/80">
{publications?.map((post: LensterPublication, index: number) => (
{publications?.map((post: any, index: number) => (
<SinglePublication key={`${post?.id}_${index}`} publication={post} />
))}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Explore: NextPage = () => {
/>
<GridItemEight className="space-y-5">
<FeedType setFeedType={setFeedType} feedType={feedType} />
<Feed feedType={feedType} />
<Feed feedType={feedType as PublicationSortCriteria} />
</GridItemEight>
<GridItemFour>
<Trending />
Expand Down
Loading