@ensnode/ponder-subgraph 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/graphql.d.ts +65 -0
- package/dist/graphql.js +814 -0
- package/dist/graphql.js.map +1 -0
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +11 -0
- package/dist/helpers.js.map +1 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.js +867 -0
- package/dist/middleware.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 NameHash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
+
import { PgliteDatabase } from 'drizzle-orm/pglite';
|
|
3
|
+
import DataLoader from 'dataloader';
|
|
4
|
+
import { TableRelationalConfig } from 'drizzle-orm';
|
|
5
|
+
import { TableConfig, PgTableExtraConfig, PgTable } from 'drizzle-orm/pg-core';
|
|
6
|
+
import { GraphQLSchema } from 'graphql';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is a graphql schema generated from a drizzle (sql) schema, initially based on ponder's.
|
|
10
|
+
* https://github.com/ponder-sh/ponder/blob/main/packages/core/src/graphql/index.ts
|
|
11
|
+
*
|
|
12
|
+
* Its goal is to mimic the subgraph graphql api for queries we've deemed relevant (see docs).
|
|
13
|
+
*
|
|
14
|
+
* 1. inlines some ponder internal types
|
|
15
|
+
* 2. implement subgraph's simpler offset pagination with first & skip w/out Page types
|
|
16
|
+
* 3. PascalCase entity names
|
|
17
|
+
* 4. Polymorphic Interfaces
|
|
18
|
+
* 5. lower-case and/or filters
|
|
19
|
+
* 6. relation id shorthand filters (i.e. domains(where: { owner_id: String }))
|
|
20
|
+
* 7. sortable id columns
|
|
21
|
+
* 8. temporarily ignores column normalization that was fixed in
|
|
22
|
+
* https://github.com/ponder-sh/ponder/pull/1517/files
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
type Drizzle<TSchema extends Schema = {
|
|
26
|
+
[name: string]: never;
|
|
27
|
+
}> = NodePgDatabase<TSchema> | PgliteDatabase<TSchema>;
|
|
28
|
+
type Schema = {
|
|
29
|
+
[name: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
declare const onchain: unique symbol;
|
|
32
|
+
type OnchainTable<T extends TableConfig & {
|
|
33
|
+
extra: PgTableExtraConfig | undefined;
|
|
34
|
+
} = TableConfig & {
|
|
35
|
+
extra: PgTableExtraConfig | undefined;
|
|
36
|
+
}> = PgTable<T> & {
|
|
37
|
+
[Key in keyof T["columns"]]: T["columns"][Key];
|
|
38
|
+
} & {
|
|
39
|
+
[onchain]: true;
|
|
40
|
+
} & {
|
|
41
|
+
enableRLS: () => Omit<OnchainTable<T>, "enableRLS">;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* the following type describes:
|
|
46
|
+
* 1. `types` — mapping a polymorphic type name to the set of entities that implement that interface
|
|
47
|
+
* ex: DomainEvent -> [TransferEvent, ...]
|
|
48
|
+
* 2. `fields` — mapping a typeName to the polymorphic type it represents
|
|
49
|
+
* ex: Domain.events -> DomainEvent
|
|
50
|
+
*
|
|
51
|
+
* NOTE: in future implementations of ponder, this information could be provided by the schema
|
|
52
|
+
* using materialized views, and most/all of this code can be removed.
|
|
53
|
+
*/
|
|
54
|
+
interface PolymorphicConfig {
|
|
55
|
+
types: Record<string, PgTable<TableConfig>[]>;
|
|
56
|
+
fields: Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
declare function buildGraphQLSchema(_schema: Schema, polymorphicConfig?: PolymorphicConfig): GraphQLSchema;
|
|
59
|
+
declare function buildDataLoaderCache({ drizzle }: {
|
|
60
|
+
drizzle: Drizzle<Schema>;
|
|
61
|
+
}): ({ table }: {
|
|
62
|
+
table: TableRelationalConfig;
|
|
63
|
+
}) => DataLoader<string, any, string>;
|
|
64
|
+
|
|
65
|
+
export { type Drizzle, type OnchainTable, type PolymorphicConfig, type Schema, buildDataLoaderCache, buildGraphQLSchema, onchain };
|