Skip to content

Commit 84f690a

Browse files
authored
Feature/users endpoint (#168)
* feat: add users rest endpoint and graph support * fix: path and return type of user endpoint * fix: nullable types on user, use kysely for getting users * feat: use sign typed data instead of message * feat: use domain signtypedmessage * feat: try to set up cache invalidation * feat: setup cache invalidation
1 parent 5989b63 commit 84f690a

File tree

22 files changed

+838
-106
lines changed

22 files changed

+838
-106
lines changed

schema.graphql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ type GetSalesResponse {
451451
data: [Sale!]
452452
}
453453

454+
type GetUsersResponse {
455+
count: Int
456+
data: [User!]
457+
}
458+
454459
"""
455460
Hypercert with metadata, contract, orders, sales and fraction information
456461
"""
@@ -755,6 +760,7 @@ type Query {
755760
metadata(first: Int, offset: Int, sort: MetadataFetchInput, where: MetadataWhereInput): GetMetadataResponse!
756761
orders(first: Int, offset: Int, sort: OrderFetchInput, where: OrderWhereInput): GetOrdersResponse!
757762
sales(first: Int, offset: Int, sort: SaleFetchInput, where: SaleWhereInput): GetSalesResponse!
763+
users(first: Int, offset: Int, where: UserWhereInput): GetUsersResponse!
758764
}
759765

760766
type Sale {
@@ -850,4 +856,19 @@ input StringSearchOptions {
850856
"""
851857
A field whose value is a generic Universally Unique Identifier: https://en.wikipedia.org/wiki/Universally_unique_identifier.
852858
"""
853-
scalar UUID
859+
scalar UUID
860+
861+
type User {
862+
"""The address of the user"""
863+
address: String!
864+
865+
"""The avatar of the user"""
866+
avatar: String
867+
868+
"""The display name of the user"""
869+
display_name: String
870+
}
871+
872+
input UserWhereInput {
873+
address: StringSearchOptions
874+
}

src/__generated__/routes/routes.ts

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__generated__/swagger.json

Lines changed: 135 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/graphql.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { container } from "tsyringe";
55
import { Client, cacheExchange, fetchExchange } from "@urql/core";
66
import { CONSTANTS } from "@hypercerts-org/sdk";
77
import { indexerEnvironment } from "../utils/constants.js";
8-
import { useResponseCache, createInMemoryCache } from "@graphql-yoga/plugin-response-cache";
8+
import {
9+
useResponseCache,
10+
createInMemoryCache,
11+
} from "@graphql-yoga/plugin-response-cache";
912

1013
const defaultQuery = `{
1114
hypercerts(first: 10) {
@@ -44,24 +47,25 @@ export const yoga = createYoga({
4447
// Registry 3rd party IOC container
4548
container: { get: (cls) => container.resolve(cls) },
4649
// Create 'schema.graphql' file with schema definition in current directory
47-
emitSchemaFile: true
50+
emitSchemaFile: true,
4851
}),
4952
graphiql: { defaultQuery },
5053
cors: {
51-
methods: ["POST"]
54+
methods: ["POST"],
5255
},
5356
graphqlEndpoint: "/v1/graphql",
5457
plugins: [
5558
useResponseCache({
5659
// global cache
5760
session: () => null,
5861
ttl: 300_000,
59-
cache
60-
})
61-
]
62+
cache,
63+
idFields: ["id", "address", "chain_id"],
64+
}),
65+
],
6266
});
6367

6468
export const urqlClient = new Client({
6569
url: `${CONSTANTS.ENDPOINTS[indexerEnvironment as "production" | "test"]}/v1/graphql`,
66-
exchanges: [cacheExchange, fetchExchange]
70+
exchanges: [cacheExchange, fetchExchange],
6771
});

src/client/kysely.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { Kysely, PostgresDialect } from "kysely";
2-
import pkg from 'pg';
2+
import pkg from "pg";
33
const { Pool } = pkg;
4-
import type { CachingDatabase } from "../types/kyselySupabase.js";
5-
import { cachingDatabaseUrl } from "../utils/constants.js";
4+
import type { CachingDatabase } from "../types/kyselySupabaseCaching.js";
5+
import { cachingDatabaseUrl, dataDatabaseUrl } from "../utils/constants.js";
6+
import { DataDatabase } from "../types/kyselySupabaseData.js";
67

7-
export const kysely = new Kysely<CachingDatabase>({
8+
export const kyselyCaching = new Kysely<CachingDatabase>({
89
dialect: new PostgresDialect({
910
pool: new Pool({
10-
connectionString: cachingDatabaseUrl
11-
})
12-
})
11+
connectionString: cachingDatabaseUrl,
12+
}),
13+
}),
14+
});
15+
16+
export const kyselyData = new Kysely<DataDatabase>({
17+
dialect: new PostgresDialect({
18+
pool: new Pool({
19+
connectionString: dataDatabaseUrl,
20+
}),
21+
}),
1322
});

0 commit comments

Comments
 (0)