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

Add slug to the Metadata & QuestChainInfo #2

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@quest-chains/sdk",
"description": "An SDK for building applications on top of Quest Chains",
"version": "0.1.14",
"version": "0.1.17",
"license": "GPL-3.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
overwrite: true
schema: 'https://api.thegraph.com/subgraphs/name/dan13ram/quest-chains-rinkeby'
schema: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-mumbai'
generates:
src/graphql/types.ts:
config:
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/badgesForUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type UserBadges = {
imageUrl?: string | null | undefined;
questChain?: {
address: string | null | undefined;
}
};
}[];
chainId: string;
};
Expand Down
16 changes: 8 additions & 8 deletions src/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ export type NetworkInfo = {
export const SUPPORTED_NETWORK_INFO: NetworkInfo = {
'0x89': {
chainId: '0x89',
subgraphName: 'dan13ram/quest-chains-polygon',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/dan13ram/quest-chains-polygon',
subgraphName: 'quest-chains/quest-chains-polygon',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-polygon',
},
'0x64': {
chainId: '0x64',
subgraphName: 'dan13ram/quest-chains-xdai',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/dan13ram/quest-chains-xdai',
subgraphName: 'quest-chains/quest-chains-xdai',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-xdai',
},
'0x5': {
chainId: '0x5',
subgraphName: 'dan13ram/quest-chains-goerli',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/dan13ram/quest-chains-goerli',
subgraphName: 'quest-chains/quest-chains-goerli',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-goerli',
},
'0x13881': {
chainId: '0x13881',
subgraphName: 'dan13ram/quest-chains-mumbai',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/dan13ram/quest-chains-mumbai',
subgraphName: 'quest-chains/quest-chains-mumbai',
subgraphUrl: 'https://api.thegraph.com/subgraphs/name/quest-chains/quest-chains-mumbai',
},
};

Expand Down
1 change: 1 addition & 0 deletions src/graphql/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fragment QuestChainInfo on QuestChain {
numCompletedQuesters
description
imageUrl
slug
quests {
questId
paused
Expand Down
16 changes: 3 additions & 13 deletions src/graphql/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ query QuestChainsInfo($limit: Int) {
}

query CreatedQuestChainsInfo($limit: Int, $user: String) {
questChains(
first: $limit
where: { createdBy: $user }
orderBy: createdAt
orderDirection: desc
) {
questChains(first: $limit, where: { createdBy: $user }, orderBy: createdAt, orderDirection: desc) {
...QuestChainInfo
}
}
Expand Down Expand Up @@ -44,13 +39,8 @@ query QuestChainSearch($search: String, $limit: Int) {
}
}

query QuestChainSearch($search: String, $limit: Int) {
Copy link
Member

@dan13ram dan13ram Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this might be a mistake?
We need this for the "search" functionality to work.
We should rather create a new query instead of replacing this.

I'm also thinking we need a query for fetching ALL slugs so that when a user is creating a new slug we can check and make sure there are no conflicts.

But I'm still worried there might be a race condition here where two people set the slug at the same time, and there is no way for us to stop that from happening.

Copy link
Member Author

@vidvidvid vidvidvid Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this might be a mistake?

there were 2 exactly queries, which were exactly the same, so i replaced one of them.

I'm also thinking we need a query for fetching ALL slugs so that when a user is creating a new slug we can check and make sure there are no conflicts.

we'd need to fetch all quest chains and return only their slugs for this to work, right?

race condition

let's not think about this edge case 😅

questChains(
first: $limit
where: { search_contains: $search, paused: false }
orderBy: createdAt
orderDirection: desc
) {
query QuestChainSearchBySlug($slug: String) {
questChains(where: { slug: $slug }) {
...QuestChainInfo
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/graphql/questChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
QuestChainInfoFragment,
QuestChainInfoQuery,
QuestChainInfoQueryVariables,
QuestChainSearchBySlugDocument,
QuestChainSearchBySlugQuery,
QuestChainSearchBySlugQueryVariables,
QuestChainSearchDocument,
QuestChainSearchQuery,
QuestChainSearchQueryVariables,
Expand Down Expand Up @@ -61,6 +64,21 @@ export const getQuestChainsFromSearch = async (chainId: string, search: string):
return data.questChains;
};

export const getQuestChainsFromSlug = async (chainId: string, slug: string): Promise<QuestChainInfoFragment[]> => {
const { data, error } = await getClient(chainId)
.query<QuestChainSearchBySlugQuery, QuestChainSearchBySlugQueryVariables>(QuestChainSearchBySlugDocument, {
slug: slug.toLowerCase(),
})
.toPromise();
if (!data) {
if (error) {
throw error;
}
return [];
}
return data.questChains;
};

export const getCreatedQuestChains = async (chainId: string, address: string): Promise<QuestChainInfoFragment[]> => {
const { data, error } = await getClient(chainId)
.query<CreatedQuestChainsInfoQuery, CreatedQuestChainsInfoQueryVariables>(CreatedQuestChainsInfoDocument, {
Expand Down
8 changes: 8 additions & 0 deletions src/metadata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
"default": "",
"examples": ["ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn"]
},
"slug": {
"$id": "#/properties/slug",
"type": "string",
"title": "The slug schema",
"description": "This property defines an optional slug for the item",
"default": "",
"examples": ["path-of-the-engaged"]
},
"animation_url": {
"$id": "#/properties/animation_url",
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions src/metadata/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Metadata = {
image_url?: string;
animation_url?: string;
external_url?: string;
slug?: string;
attributes?: {
trait_type?: string;
value: string | number;
Expand Down