Skip to content

Commit

Permalink
Merge pull request #67 from hypercerts-org/fix/field_names
Browse files Browse the repository at this point in the history
fix(fields): null fields and rename routes
  • Loading branch information
bitbeckers authored Jun 6, 2024
2 parents f5d75b1 + 6f57852 commit 1194b29
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 77 deletions.
13 changes: 5 additions & 8 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ input BasicFractionWhereInput {
}

input BasicHypercertWhereInput {
creation_block_timestamp: NumberSearchOptions
block_number: NumberSearchOptions
hypercert_id: StringSearchOptions
id: IdSearchOptions
last_block_update_timestamp: NumberSearchOptions
owner_address: StringSearchOptions
token_id: NumberSearchOptions
uri: StringSearchOptions
Expand Down Expand Up @@ -251,9 +250,9 @@ type GetOrdersResponse {

type Hypercert {
attestations: GetAttestationsResponse
block_number: BigInt
contract: Contract
contracts_id: ID
creation_block_timestamp: BigInt
fractions: GetFractionsResponse
hypercert_id: ID
id: ID!
Expand All @@ -271,8 +270,8 @@ input HypercertFetchInput {
}

input HypercertSortOptions {
block_number: SortOrder
claim_attestation_count: SortOrder
creation_block_timestamp: SortOrder
hypercert_id: SortOrder
last_block_update_timestamp: SortOrder
owner_address: SortOrder
Expand All @@ -283,12 +282,11 @@ input HypercertSortOptions {

input HypercertsWhereInput {
attestations: BasicAttestationWhereInput
block_number: NumberSearchOptions
contract: BasicContractWhereInput
creation_block_timestamp: NumberSearchOptions
fractions: BasicFractionWhereInput
hypercert_id: StringSearchOptions
id: IdSearchOptions
last_block_update_timestamp: NumberSearchOptions
metadata: BasicMetadataWhereInput
owner_address: StringSearchOptions
token_id: NumberSearchOptions
Expand Down Expand Up @@ -340,10 +338,9 @@ input MetadataSortOptions {
}

input MetadataWhereInput {
creation_block_timestamp: NumberSearchOptions
block_number: NumberSearchOptions
hypercert_id: StringSearchOptions
id: IdSearchOptions
last_block_update_timestamp: NumberSearchOptions
metadata: BasicMetadataWhereInput
owner_address: StringSearchOptions
token_id: NumberSearchOptions
Expand Down
1 change: 1 addition & 0 deletions src/client/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const yoga = createYoga({
cors: {
methods: ["POST"],
},
graphqlEndpoint: "/v1/graphql",
plugins: [
useResponseCache({
// global cache
Expand Down
1 change: 0 additions & 1 deletion src/controllers/AllowListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface CreateAllowListRequest {
totalUnits: string;
}


@Route("v1/allowlists")
@Tags("Allowlists")
export class AllowListController extends Controller {
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/enums/sortEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ registerEnumType(SortOrder, {
//TODO add sort by count
export enum HypercertSortKeys {
hypercert_id = "hypercert_id",
creation_block_timestamp = "creation_block_timestamp",
block_number = "block_number",
token_id = "token_id",
}

Expand Down
4 changes: 1 addition & 3 deletions src/graphql/schemas/inputs/hypercertsInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ export class BasicHypercertWhereInput implements WhereOptions<Hypercert> {
@Field(_ => IdSearchOptions, {nullable: true})
id?: IdSearchOptions
@Field(_ => NumberSearchOptions, {nullable: true})
creation_block_timestamp?: NumberSearchOptions;
block_number?: NumberSearchOptions;
@Field(_ => NumberSearchOptions, {nullable: true})
token_id?: NumberSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
owner_address?: StringSearchOptions;
@Field(_ => NumberSearchOptions, {nullable: true})
last_block_update_timestamp?: NumberSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
uri?: StringSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/inputs/sortOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class HypercertSortOptions implements SortOptions<Hypercert> {
@Field(_ => SortOrder, {nullable: true})
hypercert_id?: SortOrder;
@Field(_ => SortOrder, {nullable: true})
creation_block_timestamp?: SortOrder;
block_number?: SortOrder;
@Field(_ => SortOrder, {nullable: true})
token_id?: SortOrder;
@Field(_ => SortOrder, {nullable: true})
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/resolvers/attestationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AttestationResolver {
try {
const res = await this.supabaseService.getHypercerts({
where: {
contracts: {chain_id: {eq: BigInt(_att.chain_id)}, contract_address: {eq: _att.contract_address}},
contract: {chain_id: {eq: BigInt(_att.chain_id)}, contract_address: {eq: _att.contract_address}},
token_id: {eq: BigInt(_att.token_id)}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/typeDefs/attestationTypeDefs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Field, ID, ObjectType} from "type-graphql";
import {GraphQLBigInt, GraphQLJSON} from 'graphql-scalars';
import type {Json} from "../../../types/supabase.js";
import type {Json} from "../../../types/supabaseCaching.js";
import {Hypercert} from "./hypercertTypeDefs.js";
import {BasicTypeDef} from "./basicTypeDef.js";

Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/typeDefs/hypercertTypeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Hypercert extends BasicTypeDef {
@Field((_) => ID, { nullable: true })
contracts_id?: string;
@Field((_) => GraphQLBigInt, { nullable: true })
creation_block_timestamp?: bigint | number;
block_number?: bigint | number;
@Field((_) => ID, { nullable: true })
hypercert_id?: string;
@Field((_) => GraphQLBigInt, { nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/utils/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
StringSearchOptions
} from "../inputs/searchOptions.js";
import type {WhereOptions} from "../inputs/whereOptions.js";
import type {CachingDatabase} from "../../../types/supabase.js";
import type {Database as CachingDatabase} from "../../../types/supabaseCaching.js";
import {PostgrestTransformBuilder} from "@supabase/postgrest-js";


Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/utils/pagination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PostgrestTransformBuilder} from "@supabase/postgrest-js";
import type {CachingDatabase} from "../../../types/supabase.js";
import type {Database as CachingDatabase} from "../../../types/supabaseCaching.js";
import {PaginationArgs} from "../args/paginationArgs.js";

interface ApplyPagination<
Expand Down
8 changes: 1 addition & 7 deletions src/graphql/schemas/utils/sorting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PostgrestTransformBuilder} from "@supabase/postgrest-js";
import type {CachingDatabase} from "../../../types/supabase.js";
import type {Database as CachingDatabase} from "../../../types/supabaseCaching.js";
import type {OrderOptions} from "../inputs/orderOptions.js";
import {
AttestationSchemaSortOptions,
Expand Down Expand Up @@ -38,17 +38,13 @@ export const applySorting = <T extends object, QueryType extends PostgrestTransf
}][] = [];
for (const [_column, _direction] of Object.entries(value)) {
if (!_column || !_direction) continue;
console.log("Column: ", _column)
console.log("Direction: ", _direction)
// TODO resolve hacky workaround for hypercerts <> claims alias
nestedSorting.push([_column, {ascending: _direction !== SortOrder.descending}]);
}
sorting.push(...nestedSorting);
}
}

console.log(sorting);

query = sorting
.reduce(
(acc, [column, options]) => {
Expand All @@ -57,7 +53,5 @@ export const applySorting = <T extends object, QueryType extends PostgrestTransf
query
)

console.log(query);

return query as unknown as QueryType;
}
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './instrument.js';
import express, {type Express} from "express";
import express, {type Express, Router} from "express";
import "reflect-metadata";
import cors from "cors";
import {assertExists} from "./utils/assertExists.js";
Expand All @@ -25,16 +25,10 @@ const PORT = assertExists(process.env.PORT, "PORT");

const app: Express = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cors());

app.use(
"/docs",
swaggerUi.serve,
swaggerUi.setup(swaggerJson)
);

app.get('/health', (req, res) => {
const data = {
uptime: process.uptime(),
Expand All @@ -48,6 +42,12 @@ app.get('/health', (req, res) => {
// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path
app.use(yoga.graphqlEndpoint, yoga);

app.use(
"/spec",
swaggerUi.serve,
swaggerUi.setup(swaggerJson)
);

RegisterRoutes(app);

// The error handler must be registered before any other error middleware and after all controllers
Expand All @@ -58,7 +58,7 @@ app.listen(PORT, () => {
`🕸️ Running a GraphQL API server at http://localhost:${PORT}/graphql`
);

console.log(`🚀 Running Swagger docs at http://localhost:${PORT}/docs`);
console.log(`🚀 Running Swagger docs at http://localhost:${PORT}/`);

});

4 changes: 2 additions & 2 deletions src/services/SupabaseCachingService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { supabaseCaching } from "../client/supabase.js";
import type { SupabaseClient } from "@supabase/supabase-js";
import type { CachingDatabase, Tables } from "../types/supabaseCaching.js";
import type { Database as CachingDatabase, Tables } from "../types/supabaseCaching.js";
import { applyFilters } from "../graphql/schemas/utils/filters.js";
import type { GetContractsArgs } from "../graphql/schemas/args/contractArgs.js";
import type { GetMetadataArgs } from "../graphql/schemas/args/metadataArgs.js";
Expand Down Expand Up @@ -37,7 +37,7 @@ export class SupabaseCachingService {
// Claims

getHypercerts(args: GetHypercertArgs) {
const fromString = `* ${args.where?.contracts ? ", contracts!inner (*)" : ""} ${args.where?.metadata ? ", metadata!inner (*)" : ""} ${args.where?.attestations ? ", attestations!inner (*)" : ""} ${args.where?.fractions ? ", fractions!inner (*)" : ""}`;
const fromString = `* ${args.where?.contract ? ", contracts!inner (*)" : ""} ${args.where?.metadata ? ", metadata!inner (*)" : ""} ${args.where?.attestations ? ", attestations!inner (*)" : ""} ${args.where?.fractions ? ", fractions!inner (*)" : ""}`;

// TOOD build method to get count
let query = this.supabaseCaching.from("claims").select(fromString, {
Expand Down
56 changes: 16 additions & 40 deletions src/types/graphql-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export type introspection = {
"name": "BasicHypercertWhereInput",
"inputFields": [
{
"name": "creation_block_timestamp",
"name": "block_number",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
Expand All @@ -782,14 +782,6 @@ export type introspection = {
"ofType": null
}
},
{
"name": "last_block_update_timestamp",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
"ofType": null
}
},
{
"name": "owner_address",
"type": {
Expand Down Expand Up @@ -1474,28 +1466,28 @@ export type introspection = {
"args": []
},
{
"name": "contract",
"name": "block_number",
"type": {
"kind": "OBJECT",
"name": "Contract",
"kind": "SCALAR",
"name": "BigInt",
"ofType": null
},
"args": []
},
{
"name": "contracts_id",
"name": "contract",
"type": {
"kind": "SCALAR",
"name": "ID",
"kind": "OBJECT",
"name": "Contract",
"ofType": null
},
"args": []
},
{
"name": "creation_block_timestamp",
"name": "contracts_id",
"type": {
"kind": "SCALAR",
"name": "BigInt",
"name": "ID",
"ofType": null
},
"args": []
Expand Down Expand Up @@ -1615,15 +1607,15 @@ export type introspection = {
"name": "HypercertSortOptions",
"inputFields": [
{
"name": "claim_attestation_count",
"name": "block_number",
"type": {
"kind": "ENUM",
"name": "SortOrder",
"ofType": null
}
},
{
"name": "creation_block_timestamp",
"name": "claim_attestation_count",
"type": {
"kind": "ENUM",
"name": "SortOrder",
Expand Down Expand Up @@ -1693,18 +1685,18 @@ export type introspection = {
}
},
{
"name": "contract",
"name": "block_number",
"type": {
"kind": "INPUT_OBJECT",
"name": "BasicContractWhereInput",
"name": "NumberSearchOptions",
"ofType": null
}
},
{
"name": "creation_block_timestamp",
"name": "contract",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
"name": "BasicContractWhereInput",
"ofType": null
}
},
Expand Down Expand Up @@ -1732,14 +1724,6 @@ export type introspection = {
"ofType": null
}
},
{
"name": "last_block_update_timestamp",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
"ofType": null
}
},
{
"name": "metadata",
"type": {
Expand Down Expand Up @@ -2067,7 +2051,7 @@ export type introspection = {
"name": "MetadataWhereInput",
"inputFields": [
{
"name": "creation_block_timestamp",
"name": "block_number",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
Expand All @@ -2090,14 +2074,6 @@ export type introspection = {
"ofType": null
}
},
{
"name": "last_block_update_timestamp",
"type": {
"kind": "INPUT_OBJECT",
"name": "NumberSearchOptions",
"ofType": null
}
},
{
"name": "metadata",
"type": {
Expand Down

0 comments on commit 1194b29

Please sign in to comment.