Skip to content

Commit

Permalink
collictible mintHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemistgo87 committed Jul 24, 2023
1 parent ea350f1 commit c79af27
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 39 deletions.
10 changes: 9 additions & 1 deletion @types/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ declare module '*/drop.graphql' {
const defaultDocument: DocumentNode;
export const MintNft: DocumentNode;
export const GetDrop: DocumentNode;
export const GetDropPurchases: DocumentNode;

export default defaultDocument;
}
Expand All @@ -43,6 +42,15 @@ declare module '*/transfer.graphql' {
}


declare module '*/collectible.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
export const GetCollectibleHistory: DocumentNode;

export default defaultDocument;
}


declare module '*/collections.graphql' {
import { DocumentNode } from 'graphql';
const defaultDocument: DocumentNode;
Expand Down
6 changes: 5 additions & 1 deletion holaplex.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type BlockchainCost {
credits: Int!
}

type Collectible {
mintHistory: [Purchase]
}

type Collection {
"""
The blockchain address of the collection used to view it in blockchain explorers.
Expand Down Expand Up @@ -1411,6 +1415,7 @@ type Purchase {
}

type Query {
collectible: Collectible
collections: [CollectionMint]

"""
Expand All @@ -1421,7 +1426,6 @@ type Query {
"""
creditSheet: [ActionCost!]!
drop: Drop
dropPurchases: Drop

"""
Returns a list of event types that an external service can subscribe to.
Expand Down
7 changes: 6 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import Wallet from 'holaplex.graphql'
#import CollectionMint from 'holaplex.graphql'
#import Purchase from 'holaplex.graphql'
#import Drop from 'holaplex.graphql'

schema {
Expand All @@ -14,11 +15,15 @@ type Me {
wallets: [Wallet]
}

type Collectible {
mintHistory: [Purchase]
}

type Query {
drop: Drop
dropPurchases: Drop
me: Me
collections: [CollectionMint]
collectible: Collectible
}

type Mutation {
Expand Down
12 changes: 7 additions & 5 deletions src/app/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use client';
import Image from 'next/image';
import { useMemo } from 'react';
import { AssetType, CollectionMint, Holder, Purchase } from '@/graphql.types';
import { AssetType, CollectionMint, Purchase } from '@/graphql.types';
import { shorten } from '../modules/wallet';
import { MintDrop } from '@/mutations/mint.graphql';
import { ApolloError, useMutation, useQuery } from '@apollo/client';
import { GetDropPurchases, GetDrop } from '@/queries/drop.graphql';
import { GetDrop } from '@/queries/drop.graphql';
import { GetCollectibleHistory } from '@/queries/collectible.graphql';

import Link from 'next/link';
import { isNil, not, pipe } from 'ramda';
import useMe from '@/hooks/useMe';
Expand All @@ -31,14 +33,14 @@ export default function Home({ session }: HomeProps) {
const collection = dropQuery.data?.drop.collection;
const metadataJson = collection?.metadataJson;

const dropPurchasesQuery = useQuery(GetDropPurchases);
const mintHistoryQuery = useQuery(GetCollectibleHistory);
const walletAddresses = me?.wallets?.map((wallet) => wallet?.address);

const purchase = useMemo(() => {
return dropPurchasesQuery.data?.dropPurchases.purchases?.find(
return mintHistoryQuery.data?.collectible.mintHistory?.find(
(purchase: Purchase) => walletAddresses?.includes(purchase.wallet)
);
}, [dropPurchasesQuery.data?.dropPurchases.purchases, walletAddresses]);
}, [mintHistoryQuery.data?.collectible.mintHistory, walletAddresses]);

const purchased = pipe(isNil, not)(purchase);
const [mint, { loading }] = useMutation<MintData>(MintDrop, {
Expand Down
17 changes: 15 additions & 2 deletions src/graphql.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export type BlockchainCost = {
credits: Scalars['Int'];
};

export type Collectible = {
__typename?: 'Collectible';
mintHistory?: Maybe<Array<Maybe<Purchase>>>;
};

export type Collection = {
__typename?: 'Collection';
/**
Expand Down Expand Up @@ -1366,6 +1371,7 @@ export type Purchase = {

export type Query = {
__typename?: 'Query';
collectible?: Maybe<Collectible>;
collections?: Maybe<Array<Maybe<CollectionMint>>>;
/**
* Returns a list of `ActionCost` which represents the cost of each action on different blockchains.
Expand All @@ -1375,7 +1381,6 @@ export type Query = {
*/
creditSheet: Array<ActionCost>;
drop?: Maybe<Drop>;
dropPurchases?: Maybe<Drop>;
/**
* Returns a list of event types that an external service can subscribe to.
*
Expand Down Expand Up @@ -1651,6 +1656,7 @@ export type ResolversTypes = {
Blockchain: Blockchain;
BlockchainCost: ResolverTypeWrapper<BlockchainCost>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
Collectible: ResolverTypeWrapper<Collectible>;
Collection: ResolverTypeWrapper<Collection>;
CollectionCreator: ResolverTypeWrapper<CollectionCreator>;
CollectionMint: ResolverTypeWrapper<CollectionMint>;
Expand Down Expand Up @@ -1757,6 +1763,7 @@ export type ResolversParentTypes = {
Affiliation: ResolversUnionTypes['Affiliation'];
BlockchainCost: BlockchainCost;
Boolean: Scalars['Boolean'];
Collectible: Collectible;
Collection: Collection;
CollectionCreator: CollectionCreator;
CollectionMint: CollectionMint;
Expand Down Expand Up @@ -1884,6 +1891,11 @@ export type BlockchainCostResolvers<ContextType = any, ParentType extends Resolv
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type CollectibleResolvers<ContextType = any, ParentType extends ResolversParentTypes['Collectible'] = ResolversParentTypes['Collectible']> = {
mintHistory?: Resolver<Maybe<Array<Maybe<ResolversTypes['Purchase']>>>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type CollectionResolvers<ContextType = any, ParentType extends ResolversParentTypes['Collection'] = ResolversParentTypes['Collection']> = {
address?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
blockchain?: Resolver<ResolversTypes['Blockchain'], ParentType, ContextType>;
Expand Down Expand Up @@ -2278,10 +2290,10 @@ export type PurchaseResolvers<ContextType = any, ParentType extends ResolversPar
};

export type QueryResolvers<ContextType = any, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query']> = {
collectible?: Resolver<Maybe<ResolversTypes['Collectible']>, ParentType, ContextType>;
collections?: Resolver<Maybe<Array<Maybe<ResolversTypes['CollectionMint']>>>, ParentType, ContextType>;
creditSheet?: Resolver<Array<ResolversTypes['ActionCost']>, ParentType, ContextType>;
drop?: Resolver<Maybe<ResolversTypes['Drop']>, ParentType, ContextType>;
dropPurchases?: Resolver<Maybe<ResolversTypes['Drop']>, ParentType, ContextType>;
eventTypes?: Resolver<Array<ResolversTypes['EventType']>, ParentType, ContextType>;
invite?: Resolver<Maybe<ResolversTypes['Invite']>, ParentType, ContextType, RequireFields<QueryInviteArgs, 'id'>>;
me?: Resolver<Maybe<ResolversTypes['Me']>, ParentType, ContextType>;
Expand Down Expand Up @@ -2370,6 +2382,7 @@ export type Resolvers<ContextType = any> = {
ActionCost?: ActionCostResolvers<ContextType>;
Affiliation?: AffiliationResolvers<ContextType>;
BlockchainCost?: BlockchainCostResolvers<ContextType>;
Collectible?: CollectibleResolvers<ContextType>;
Collection?: CollectionResolvers<ContextType>;
CollectionCreator?: CollectionCreatorResolvers<ContextType>;
CollectionMint?: CollectionMintResolvers<ContextType>;
Expand Down
34 changes: 18 additions & 16 deletions src/pages/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
TransferAssetPayload,
TransferAssetInput,
Blockchain,
AssetType
AssetType,
Collection,
Collectible
} from '@/graphql.types';
import { Session } from 'next-auth';
import { MintNft } from '@/mutations/drop.graphql';
Expand Down Expand Up @@ -80,7 +82,7 @@ export const queryResolvers: QueryResolvers<AppContext> = {

return data.project.drop as Drop;
},
async dropPurchases(_a, _b, { dataSources: { holaplex } }) {
async collectible(_a, _b, { dataSources: { holaplex } }) {
const { data } = await holaplex.query<GetDropData, GetDropVars>({
fetchPolicy: 'network-only',
query: GetProjectDropPurchases,
Expand All @@ -90,20 +92,7 @@ export const queryResolvers: QueryResolvers<AppContext> = {
}
});

return data.project.drop as Drop;
},
async me(_a, _b, { session, dataSources: { user } }) {
if (!session) {
return null;
}

const me = await user.get(session.user?.email);

if (me) {
return me;
}

return null;
return { mintHistory: data.project.drop?.purchases } as Collectible;
},
async collections(_a, _b, { session, dataSources: { holaplex, db } }) {
if (!session) {
Expand All @@ -130,6 +119,19 @@ export const queryResolvers: QueryResolvers<AppContext> = {
});

return data.project.customer?.mints as [CollectionMint];
},
async me(_a, _b, { session, dataSources: { user } }) {
if (!session) {
return null;
}

const me = await user.get(session.user?.email);

if (me) {
return me;
}

return null;
}
};

Expand Down
11 changes: 11 additions & 0 deletions src/queries/collectible.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query GetCollectibleHistory {
collectible {
mintHistory {
id
mintId
dropId
wallet
status
}
}
}
13 changes: 0 additions & 13 deletions src/queries/drop.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,3 @@ query GetDrop {
}
}
}

query GetDropPurchases {
dropPurchases {
id
purchases {
id
mintId
dropId
wallet
status
}
}
}

0 comments on commit c79af27

Please sign in to comment.