@codex-data/sdk 0.6.2 → 1.0.0-rc2
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/dist/resources/generated_mutations/CreateApiTokens.graphql +9 -0
- package/dist/resources/generated_mutations/CreateWebhooks.graphql +80 -0
- package/dist/resources/generated_mutations/DeleteApiToken.graphql +3 -0
- package/{src/sdk/graphql → dist/resources/generated_mutations}/DeleteWebhooks.graphql +1 -1
- package/dist/resources/generated_queries/ApiToken.graphql +9 -0
- package/dist/resources/generated_queries/ApiTokens.graphql +9 -0
- package/dist/resources/generated_queries/Balances.graphql +12 -0
- package/dist/resources/generated_queries/ChartUrls.graphql +7 -0
- package/dist/resources/generated_queries/FilterExchanges.graphql +43 -0
- package/dist/resources/generated_queries/FilterNftCollections.graphql +569 -0
- package/dist/resources/generated_queries/FilterNftParallelAssets.graphql +60 -0
- package/dist/resources/generated_queries/FilterNftPoolCollections.graphql +71 -0
- package/dist/resources/generated_queries/FilterNftPools.graphql +124 -0
- package/dist/resources/generated_queries/FilterPairs.graphql +343 -0
- package/dist/resources/generated_queries/FilterTokens.graphql +282 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/GetBars.graphql +21 -9
- package/dist/resources/generated_queries/GetCommunityNotes.graphql +20 -0
- package/dist/resources/generated_queries/GetDetailedNftStats.graphql +831 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/GetDetailedPairStats.graphql +372 -373
- package/dist/resources/generated_queries/GetDetailedPairsStats.graphql +924 -0
- package/dist/resources/generated_queries/GetEventLabels.graphql +24 -0
- package/dist/resources/generated_queries/GetExchanges.graphql +12 -0
- package/dist/resources/generated_queries/GetLatestPairs.graphql +57 -0
- package/dist/resources/generated_queries/GetLatestTokens.graphql +39 -0
- package/dist/resources/generated_queries/GetNetworkStats.graphql +13 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/GetNetworkStatus.graphql +2 -1
- package/{src/sdk/graphql → dist/resources/generated_queries}/GetNetworks.graphql +1 -0
- package/dist/resources/generated_queries/GetNftAssets.graphql +59 -0
- package/dist/resources/generated_queries/GetNftCollectionMetadata.graphql +75 -0
- package/dist/resources/generated_queries/GetNftContracts.graphql +39 -0
- package/dist/resources/generated_queries/GetNftEvents.graphql +54 -0
- package/dist/resources/generated_queries/GetNftPool.graphql +74 -0
- package/dist/resources/generated_queries/GetNftPoolCollection.graphql +33 -0
- package/dist/resources/generated_queries/GetNftPoolCollectionsByExchange.graphql +38 -0
- package/dist/resources/generated_queries/GetNftPoolEvents.graphql +41 -0
- package/dist/resources/generated_queries/GetNftPoolStats.graphql +40 -0
- package/dist/resources/generated_queries/GetNftPoolsByCollectionAndExchange.graphql +89 -0
- package/dist/resources/generated_queries/GetNftPoolsByOwner.graphql +89 -0
- package/dist/resources/generated_queries/GetParallelAssets.graphql +50 -0
- package/dist/resources/generated_queries/GetParallelCardChanges.graphql +57 -0
- package/dist/resources/generated_queries/GetPrimePoolAssets.graphql +32 -0
- package/dist/resources/generated_queries/GetPrimePoolEvents.graphql +38 -0
- package/dist/resources/generated_queries/GetPrimePools.graphql +62 -0
- package/dist/resources/generated_queries/GetSimulateTokenContractResults.graphql +128 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/GetSymbol.graphql +7 -7
- package/dist/resources/generated_queries/GetTokenCount.graphql +3 -0
- package/dist/resources/generated_queries/GetTokenEvents.graphql +49 -0
- package/dist/resources/generated_queries/GetTokenEventsForMaker.graphql +49 -0
- package/dist/resources/generated_queries/GetTokenInfo.graphql +18 -0
- package/dist/resources/generated_queries/GetTokenPrices.graphql +9 -0
- package/dist/resources/generated_queries/GetTokensInfo.graphql +18 -0
- package/dist/resources/generated_queries/GetUniV3Ticks.graphql +22 -0
- package/dist/resources/generated_queries/GetWebhooks.graphql +36 -0
- package/dist/resources/generated_queries/Holders.graphql +14 -0
- package/dist/resources/generated_queries/LiquidityLocks.graphql +26 -0
- package/dist/resources/generated_queries/LiquidityMetadata.graphql +17 -0
- package/dist/resources/generated_queries/ListFavoriteTokens.graphql +59 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/ListPairsForToken.graphql +79 -41
- package/dist/resources/generated_queries/ListPairsWithMetadataForToken.graphql +286 -0
- package/{src/sdk/graphql → dist/resources/generated_queries}/ListTopTokens.graphql +23 -16
- package/dist/resources/generated_queries/NftHolders.graphql +12 -0
- package/{src/sdk/graphql/OnPairMetadataUpdated.graphql → dist/resources/generated_queries/PairMetadata.graphql} +21 -3
- package/dist/resources/generated_queries/PrimeBalance.graphql +12 -0
- package/dist/resources/generated_queries/PrimeHolders.graphql +13 -0
- package/dist/resources/generated_queries/SearchNfts.graphql +35 -0
- package/dist/resources/generated_queries/Token.graphql +63 -0
- package/dist/resources/generated_queries/TokenLifecycleEvents.graphql +22 -0
- package/{src/sdk/graphql/GetSparklines.graphql → dist/resources/generated_queries/TokenSparklines.graphql} +2 -2
- package/dist/resources/generated_queries/Tokens.graphql +63 -0
- package/dist/resources/generated_queries/WalletNftCollectionAssets.graphql +11 -0
- package/dist/resources/generated_queries/WalletNftCollections.graphql +10 -0
- package/dist/resources/generated_subscriptions/OnBarsUpdated.graphql +513 -0
- package/{src/sdk/graphql → dist/resources/generated_subscriptions}/OnDetailedStatsUpdated.graphql +119 -111
- package/dist/resources/generated_subscriptions/OnEventLabelCreated.graphql +11 -0
- package/dist/resources/generated_subscriptions/OnEventsCreated.graphql +46 -0
- package/dist/resources/generated_subscriptions/OnLatestPairUpdated.graphql +42 -0
- package/dist/resources/generated_subscriptions/OnLatestTokens.graphql +37 -0
- package/{src/sdk/graphql → dist/resources/generated_subscriptions}/OnNftAssetsCreated.graphql +30 -17
- package/dist/resources/generated_subscriptions/OnNftEventsCreated.graphql +36 -0
- package/dist/resources/generated_subscriptions/OnNftPoolEventsCreated.graphql +37 -0
- package/dist/resources/generated_subscriptions/OnPairMetadataUpdated.graphql +73 -0
- package/{src/sdk/graphql → dist/resources/generated_subscriptions}/OnPriceUpdated.graphql +1 -1
- package/dist/resources/generated_subscriptions/OnPricesUpdated.graphql +9 -0
- package/dist/resources/generated_subscriptions/OnSimulateTokenContract.graphql +121 -0
- package/dist/resources/generated_subscriptions/OnTokenEventsCreated.graphql +39 -0
- package/dist/resources/generated_subscriptions/OnTokenLifecycleEventsCreated.graphql +18 -0
- package/dist/resources/generated_subscriptions/OnUnconfirmedEventsCreated.graphql +32 -0
- package/dist/resources/graphql.d.ts +175 -1
- package/dist/resources/graphql.d.ts.map +1 -1
- package/dist/resources/graphql.js.map +1 -1
- package/dist/resources/graphql.schema.json +1901 -2
- package/dist/resources/graphql.ts +199 -1
- package/dist/resources/schema.graphql +230 -1
- package/dist/scripts/buildSdk.d.ts +2 -0
- package/dist/scripts/buildSdk.d.ts.map +1 -0
- package/dist/scripts/buildSdk.js +135 -0
- package/dist/scripts/buildSdk.js.map +1 -0
- package/dist/scripts/generateGraphql.d.ts +30 -0
- package/dist/scripts/generateGraphql.d.ts.map +1 -0
- package/dist/scripts/generateGraphql.js +179 -0
- package/dist/scripts/generateGraphql.js.map +1 -0
- package/dist/sdk/Mutation.d.ts +5 -8
- package/dist/sdk/Mutation.d.ts.map +1 -1
- package/dist/sdk/Mutation.js +3 -0
- package/dist/sdk/Mutation.js.map +1 -1
- package/dist/sdk/Query.d.ts +65 -13
- package/dist/sdk/Query.d.ts.map +1 -1
- package/dist/sdk/Query.js +65 -12
- package/dist/sdk/Query.js.map +1 -1
- package/dist/sdk/Subscribe.d.ts +18 -11
- package/dist/sdk/Subscribe.d.ts.map +1 -1
- package/dist/sdk/Subscribe.js +112 -9
- package/dist/sdk/Subscribe.js.map +1 -1
- package/dist/sdk/generated/gql.d.ts +646 -66
- package/dist/sdk/generated/gql.d.ts.map +1 -1
- package/dist/sdk/generated/gql.js +85 -22
- package/dist/sdk/generated/gql.js.map +1 -1
- package/dist/sdk/generated/graphql.d.ts +8422 -2087
- package/dist/sdk/generated/graphql.d.ts.map +1 -1
- package/dist/sdk/generated/graphql.js +88 -25
- package/dist/sdk/generated/graphql.js.map +1 -1
- package/package.json +12 -4
- package/src/resources/generated_mutations/CreateApiTokens.graphql +9 -0
- package/src/resources/generated_mutations/CreateWebhooks.graphql +80 -0
- package/src/resources/generated_mutations/DeleteApiToken.graphql +3 -0
- package/src/resources/generated_mutations/DeleteWebhooks.graphql +5 -0
- package/src/resources/generated_queries/ApiToken.graphql +9 -0
- package/src/resources/generated_queries/ApiTokens.graphql +9 -0
- package/src/resources/generated_queries/Balances.graphql +12 -0
- package/src/resources/generated_queries/ChartUrls.graphql +7 -0
- package/src/resources/generated_queries/FilterExchanges.graphql +43 -0
- package/src/resources/generated_queries/FilterNftCollections.graphql +569 -0
- package/src/resources/generated_queries/FilterNftParallelAssets.graphql +60 -0
- package/src/resources/generated_queries/FilterNftPoolCollections.graphql +71 -0
- package/src/resources/generated_queries/FilterNftPools.graphql +124 -0
- package/src/resources/generated_queries/FilterPairs.graphql +343 -0
- package/src/resources/generated_queries/FilterTokens.graphql +282 -0
- package/src/resources/generated_queries/GetBars.graphql +44 -0
- package/src/resources/generated_queries/GetCommunityNotes.graphql +20 -0
- package/src/resources/generated_queries/GetDetailedNftStats.graphql +831 -0
- package/src/resources/generated_queries/GetDetailedPairStats.graphql +940 -0
- package/src/resources/generated_queries/GetDetailedPairsStats.graphql +924 -0
- package/src/resources/generated_queries/GetEventLabels.graphql +24 -0
- package/src/resources/generated_queries/GetExchanges.graphql +12 -0
- package/src/resources/generated_queries/GetLatestPairs.graphql +57 -0
- package/src/resources/generated_queries/GetLatestTokens.graphql +39 -0
- package/src/resources/generated_queries/GetNetworkStats.graphql +13 -0
- package/src/resources/generated_queries/GetNetworkStatus.graphql +8 -0
- package/src/resources/generated_queries/GetNetworks.graphql +7 -0
- package/src/resources/generated_queries/GetNftAssets.graphql +59 -0
- package/src/resources/generated_queries/GetNftCollectionMetadata.graphql +75 -0
- package/src/resources/generated_queries/GetNftContracts.graphql +39 -0
- package/src/resources/generated_queries/GetNftEvents.graphql +54 -0
- package/src/resources/generated_queries/GetNftPool.graphql +74 -0
- package/src/resources/generated_queries/GetNftPoolCollection.graphql +33 -0
- package/src/resources/generated_queries/GetNftPoolCollectionsByExchange.graphql +38 -0
- package/src/resources/generated_queries/GetNftPoolEvents.graphql +41 -0
- package/src/resources/generated_queries/GetNftPoolStats.graphql +40 -0
- package/src/resources/generated_queries/GetNftPoolsByCollectionAndExchange.graphql +89 -0
- package/src/resources/generated_queries/GetNftPoolsByOwner.graphql +89 -0
- package/src/resources/generated_queries/GetParallelAssets.graphql +50 -0
- package/src/resources/generated_queries/GetParallelCardChanges.graphql +57 -0
- package/src/resources/generated_queries/GetPrimePoolAssets.graphql +32 -0
- package/src/resources/generated_queries/GetPrimePoolEvents.graphql +38 -0
- package/src/resources/generated_queries/GetPrimePools.graphql +62 -0
- package/src/resources/generated_queries/GetSimulateTokenContractResults.graphql +128 -0
- package/src/resources/generated_queries/GetSymbol.graphql +11 -0
- package/src/resources/generated_queries/GetTokenCount.graphql +3 -0
- package/src/resources/generated_queries/GetTokenEvents.graphql +49 -0
- package/src/resources/generated_queries/GetTokenEventsForMaker.graphql +49 -0
- package/src/resources/generated_queries/GetTokenInfo.graphql +18 -0
- package/src/resources/generated_queries/GetTokenPrices.graphql +9 -0
- package/src/resources/generated_queries/GetTokensInfo.graphql +18 -0
- package/src/resources/generated_queries/GetUniV3Ticks.graphql +22 -0
- package/src/resources/generated_queries/GetWebhooks.graphql +36 -0
- package/src/resources/generated_queries/Holders.graphql +14 -0
- package/src/resources/generated_queries/LiquidityLocks.graphql +26 -0
- package/src/resources/generated_queries/LiquidityMetadata.graphql +17 -0
- package/src/resources/generated_queries/ListFavoriteTokens.graphql +59 -0
- package/src/resources/generated_queries/ListPairsForToken.graphql +143 -0
- package/src/resources/generated_queries/ListPairsWithMetadataForToken.graphql +286 -0
- package/src/resources/generated_queries/ListTopTokens.graphql +55 -0
- package/src/resources/generated_queries/NftHolders.graphql +12 -0
- package/src/resources/generated_queries/PairMetadata.graphql +73 -0
- package/src/resources/generated_queries/PrimeBalance.graphql +12 -0
- package/src/resources/generated_queries/PrimeHolders.graphql +13 -0
- package/src/resources/generated_queries/SearchNfts.graphql +35 -0
- package/src/resources/generated_queries/Token.graphql +63 -0
- package/src/resources/generated_queries/TokenLifecycleEvents.graphql +22 -0
- package/src/resources/generated_queries/TokenSparklines.graphql +10 -0
- package/src/resources/generated_queries/Tokens.graphql +63 -0
- package/src/resources/generated_queries/WalletNftCollectionAssets.graphql +11 -0
- package/src/resources/generated_queries/WalletNftCollections.graphql +10 -0
- package/src/resources/generated_subscriptions/OnBarsUpdated.graphql +513 -0
- package/src/resources/generated_subscriptions/OnDetailedStatsUpdated.graphql +332 -0
- package/src/resources/generated_subscriptions/OnEventLabelCreated.graphql +11 -0
- package/src/resources/generated_subscriptions/OnEventsCreated.graphql +46 -0
- package/src/resources/generated_subscriptions/OnLatestPairUpdated.graphql +42 -0
- package/src/resources/generated_subscriptions/OnLatestTokens.graphql +37 -0
- package/src/resources/generated_subscriptions/OnNftAssetsCreated.graphql +42 -0
- package/src/resources/generated_subscriptions/OnNftEventsCreated.graphql +36 -0
- package/src/resources/generated_subscriptions/OnNftPoolEventsCreated.graphql +37 -0
- package/src/resources/generated_subscriptions/OnPairMetadataUpdated.graphql +73 -0
- package/src/resources/generated_subscriptions/OnPriceUpdated.graphql +9 -0
- package/src/resources/generated_subscriptions/OnPricesUpdated.graphql +9 -0
- package/src/resources/generated_subscriptions/OnSimulateTokenContract.graphql +121 -0
- package/src/resources/generated_subscriptions/OnTokenEventsCreated.graphql +39 -0
- package/src/resources/generated_subscriptions/OnTokenLifecycleEventsCreated.graphql +18 -0
- package/src/resources/generated_subscriptions/OnUnconfirmedEventsCreated.graphql +32 -0
- package/src/resources/graphql.schema.json +1901 -2
- package/src/resources/graphql.ts +199 -1
- package/src/resources/schema.graphql +230 -1
- package/src/scripts/buildSdk.ts +173 -0
- package/src/scripts/generateGraphql.ts +236 -0
- package/src/sdk/Mutation.ts +13 -4
- package/src/sdk/Query.ts +254 -35
- package/src/sdk/Subscribe.ts +231 -42
- package/src/sdk/generated/gql.ts +359 -44
- package/src/sdk/generated/graphql.ts +928 -129
- package/dist/sdk/Query.test.d.ts +0 -2
- package/dist/sdk/Query.test.d.ts.map +0 -1
- package/dist/sdk/Query.test.js +0 -50
- package/dist/sdk/Query.test.js.map +0 -1
- package/src/sdk/Query.test.ts +0 -40
- package/src/sdk/graphql/CreateWebhooks.graphql +0 -464
- package/src/sdk/graphql/FilterExchanges.graphql +0 -23
- package/src/sdk/graphql/FilterPairs.graphql +0 -126
- package/src/sdk/graphql/FilterTokens.graphql +0 -131
- package/src/sdk/graphql/GetPrice.graphql +0 -9
- package/src/sdk/graphql/GetTokens.graphql +0 -14
- package/src/sdk/graphql/GetWebhooks.graphql +0 -120
- package/src/sdk/graphql/OnBarsUpdated.graphql +0 -68
- package/src/sdk/graphql/OnEventsCreated.graphql +0 -62
- package/src/sdk/graphql/OnNftEventsCreated.graphql +0 -83
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import camelCase from "lodash/camelCase";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
const GENERATED_SUBSCRIPTIONS_DIRECTORY = path.join(
|
|
6
|
+
__dirname,
|
|
7
|
+
"..",
|
|
8
|
+
"resources",
|
|
9
|
+
"generated_subscriptions",
|
|
10
|
+
);
|
|
11
|
+
const GENERATED_MUTATIONS_DIRECTORY = path.join(
|
|
12
|
+
__dirname,
|
|
13
|
+
"..",
|
|
14
|
+
"resources",
|
|
15
|
+
"generated_mutations",
|
|
16
|
+
);
|
|
17
|
+
const GENERATED_QUERIES_DIRECTORY = path.join(
|
|
18
|
+
__dirname,
|
|
19
|
+
"..",
|
|
20
|
+
"resources",
|
|
21
|
+
"generated_queries",
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
class Subscription {
|
|
25
|
+
constructor(private subscriptionName: string) {}
|
|
26
|
+
pre() {
|
|
27
|
+
return `${this.subscriptionName}SubscriptionVariables, ${this.subscriptionName}Subscription`;
|
|
28
|
+
}
|
|
29
|
+
main() {
|
|
30
|
+
const graphqlString = fs.readFileSync(
|
|
31
|
+
path.join(
|
|
32
|
+
GENERATED_SUBSCRIPTIONS_DIRECTORY,
|
|
33
|
+
this.subscriptionName + ".graphql",
|
|
34
|
+
),
|
|
35
|
+
"utf8",
|
|
36
|
+
);
|
|
37
|
+
return `${camelCase(this.subscriptionName)} = async (vars: ${
|
|
38
|
+
this.subscriptionName
|
|
39
|
+
}SubscriptionVariables, sink: Sink<ExecutionResult<${
|
|
40
|
+
this.subscriptionName
|
|
41
|
+
}Subscription>>) => this.sdk.subscribe(\`${graphqlString}\`, vars, sink);`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class Mutation {
|
|
46
|
+
constructor(private mutationName: string) {}
|
|
47
|
+
pre() {
|
|
48
|
+
return `${this.mutationName}Document,
|
|
49
|
+
${this.mutationName}MutationVariables`;
|
|
50
|
+
}
|
|
51
|
+
main() {
|
|
52
|
+
return `${camelCase(this.mutationName)} = async (vars: ${
|
|
53
|
+
this.mutationName
|
|
54
|
+
}MutationVariables) => this.sdk.mutation(${
|
|
55
|
+
this.mutationName
|
|
56
|
+
}Document, vars);`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class Query {
|
|
61
|
+
constructor(private queryName: string) {}
|
|
62
|
+
|
|
63
|
+
pre() {
|
|
64
|
+
return `${this.queryName}Document,
|
|
65
|
+
${this.queryName}QueryVariables`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main() {
|
|
69
|
+
return `${camelCase(this.queryName)} = async (vars: ${
|
|
70
|
+
this.queryName
|
|
71
|
+
}QueryVariables) => this.sdk.query(${this.queryName}Document, vars);`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
class SDK {
|
|
76
|
+
private queries: Query[] = [];
|
|
77
|
+
private mutations: Mutation[] = [];
|
|
78
|
+
private subscriptions: Subscription[] = [];
|
|
79
|
+
|
|
80
|
+
constructor() {
|
|
81
|
+
this.initialize();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
initialize() {
|
|
85
|
+
// crawl the generatedQueries and then create the typescript code for that query.
|
|
86
|
+
const queries = fs.readdirSync(GENERATED_QUERIES_DIRECTORY);
|
|
87
|
+
const mutations = fs.readdirSync(GENERATED_MUTATIONS_DIRECTORY);
|
|
88
|
+
const subscriptions = fs.readdirSync(GENERATED_SUBSCRIPTIONS_DIRECTORY);
|
|
89
|
+
|
|
90
|
+
for (const file of queries) {
|
|
91
|
+
this.queries.push(new Query(path.basename(file, ".graphql")));
|
|
92
|
+
}
|
|
93
|
+
for (const file of mutations) {
|
|
94
|
+
this.mutations.push(new Mutation(path.basename(file, ".graphql")));
|
|
95
|
+
}
|
|
96
|
+
for (const file of subscriptions) {
|
|
97
|
+
this.subscriptions.push(
|
|
98
|
+
new Subscription(path.basename(file, ".graphql")),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
printSubscriptions(): string {
|
|
104
|
+
return `
|
|
105
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT IT DIRECTLY
|
|
106
|
+
import {
|
|
107
|
+
${this.subscriptions.map((q) => " " + q.pre()).join(",\n")}
|
|
108
|
+
} from "./generated/graphql";
|
|
109
|
+
import { Codex } from "./index";
|
|
110
|
+
import { ExecutionResult, Sink } from "graphql-ws";
|
|
111
|
+
|
|
112
|
+
export class Subscribe {
|
|
113
|
+
constructor(private sdk: Codex) {}
|
|
114
|
+
${this.subscriptions.map((q) => q.main()).join("\n")}
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
printMutations(): string {
|
|
120
|
+
return `
|
|
121
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT IT DIRECTLY
|
|
122
|
+
import {
|
|
123
|
+
${this.mutations.map((q) => " " + q.pre()).join(",\n")}
|
|
124
|
+
} from "./generated/graphql";
|
|
125
|
+
import { Codex } from "./index";
|
|
126
|
+
|
|
127
|
+
export class Mutation {
|
|
128
|
+
constructor(private sdk: Codex) {}
|
|
129
|
+
${this.mutations.map((q) => q.main()).join("\n")}
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
printQueries(): string {
|
|
135
|
+
return `
|
|
136
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT IT DIRECTLY
|
|
137
|
+
import {
|
|
138
|
+
${this.queries.map((q) => " " + q.pre()).join(",\n")}
|
|
139
|
+
} from "./generated/graphql";
|
|
140
|
+
import { Codex } from "./index";
|
|
141
|
+
|
|
142
|
+
export class Query {
|
|
143
|
+
constructor(private sdk: Codex) {}
|
|
144
|
+
${this.queries.map((q) => q.main()).join("\n")}
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
output() {
|
|
150
|
+
fs.writeFileSync(
|
|
151
|
+
path.join(__dirname, "..", "sdk", "Subscribe.ts"),
|
|
152
|
+
this.printSubscriptions(),
|
|
153
|
+
"utf8",
|
|
154
|
+
);
|
|
155
|
+
fs.writeFileSync(
|
|
156
|
+
path.join(__dirname, "..", "sdk", "Mutation.ts"),
|
|
157
|
+
this.printMutations(),
|
|
158
|
+
"utf8",
|
|
159
|
+
);
|
|
160
|
+
fs.writeFileSync(
|
|
161
|
+
path.join(__dirname, "..", "sdk", "Query.ts"),
|
|
162
|
+
this.printQueries(),
|
|
163
|
+
"utf8",
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function run() {
|
|
169
|
+
const sdk = new SDK();
|
|
170
|
+
sdk.output();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
run().then(() => process.exit());
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as gql from "gql-query-builder";
|
|
3
|
+
import VariableOptions from "gql-query-builder/build/VariableOptions";
|
|
4
|
+
import { mkdirp } from "mkdirp";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
type SchemaTypeDefinition = {
|
|
8
|
+
kind:
|
|
9
|
+
| "NON_NULL"
|
|
10
|
+
| "SCALAR"
|
|
11
|
+
| "LIST"
|
|
12
|
+
| "OBJECT"
|
|
13
|
+
| "INPUT_OBJECT"
|
|
14
|
+
| "ENUM"
|
|
15
|
+
| "UNION"
|
|
16
|
+
| undefined
|
|
17
|
+
| null;
|
|
18
|
+
name?: string | null;
|
|
19
|
+
ofType?: SchemaTypeDefinition | null;
|
|
20
|
+
isDeprecated?: boolean | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type SchemaType = {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string | null;
|
|
26
|
+
type: SchemaTypeDefinition;
|
|
27
|
+
isDeprecated?: boolean | null;
|
|
28
|
+
fields?: SchemaType[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type Fields = Array<string | { [key: string]: Fields }>;
|
|
32
|
+
|
|
33
|
+
function capitalize(str: string) {
|
|
34
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const getLeafType = (
|
|
38
|
+
type: SchemaTypeDefinition,
|
|
39
|
+
allTypes: SchemaType[],
|
|
40
|
+
result: Fields,
|
|
41
|
+
currentName: string,
|
|
42
|
+
level = 0,
|
|
43
|
+
): Fields => {
|
|
44
|
+
if (level > 8 || !type?.kind || type.kind === "UNION" || type.isDeprecated)
|
|
45
|
+
return result;
|
|
46
|
+
|
|
47
|
+
// If it's a scalar, return the name
|
|
48
|
+
if (type.kind === "SCALAR" || type.kind === "ENUM")
|
|
49
|
+
return [...result, currentName!];
|
|
50
|
+
|
|
51
|
+
// If it's an object resolve it.
|
|
52
|
+
if (type.kind === "OBJECT") {
|
|
53
|
+
// For each of the fields of the subtype, resolve them
|
|
54
|
+
const subType = allTypes.find((t) => t.name === type.name);
|
|
55
|
+
const subTypeLeaves = (subType?.fields ?? [])
|
|
56
|
+
.filter((t) => !t.isDeprecated)
|
|
57
|
+
.map((f: SchemaType) =>
|
|
58
|
+
getLeafType(f.type, allTypes, [], f.name, level + 1),
|
|
59
|
+
)
|
|
60
|
+
.flat();
|
|
61
|
+
return [
|
|
62
|
+
...result,
|
|
63
|
+
...(level === 0 ? subTypeLeaves : [{ [currentName]: subTypeLeaves }]),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If it's a list, resolve the first object type
|
|
68
|
+
if (type.kind === "LIST")
|
|
69
|
+
return getLeafType(type.ofType!, allTypes, [...result], currentName, level);
|
|
70
|
+
|
|
71
|
+
// If it's required, resolve the first object type
|
|
72
|
+
if (type.kind === "NON_NULL")
|
|
73
|
+
return getLeafType(type.ofType!, allTypes, [...result], currentName, level);
|
|
74
|
+
|
|
75
|
+
throw new Error(`Unknown type ${type.name} ${type.kind}`);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const getLeafArgs = (
|
|
79
|
+
type: SchemaTypeDefinition,
|
|
80
|
+
result: VariableOptions,
|
|
81
|
+
): VariableOptions => {
|
|
82
|
+
if (
|
|
83
|
+
type.kind === "NON_NULL" &&
|
|
84
|
+
["INPUT_OBJECT", "SCALAR", "OBJECT", "ENUM"].includes(
|
|
85
|
+
type.ofType?.kind as string,
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
return { ...result, type: `${type.ofType!.name!}!` };
|
|
89
|
+
|
|
90
|
+
// If it's a scalar, return the name
|
|
91
|
+
if (
|
|
92
|
+
type.kind === "SCALAR" ||
|
|
93
|
+
type.kind === "OBJECT" ||
|
|
94
|
+
type.kind === "ENUM" ||
|
|
95
|
+
type.kind === "INPUT_OBJECT"
|
|
96
|
+
)
|
|
97
|
+
return { ...result, type: type.name!, value: null };
|
|
98
|
+
|
|
99
|
+
// If it's a list, resolve the first object type
|
|
100
|
+
if (type.kind === "LIST")
|
|
101
|
+
return getLeafArgs(type.ofType!, { ...result, list: true });
|
|
102
|
+
|
|
103
|
+
// If it's required, resolve the first object type
|
|
104
|
+
if (type.kind === "NON_NULL")
|
|
105
|
+
return getLeafArgs(type.ofType!, { ...result, required: true });
|
|
106
|
+
|
|
107
|
+
throw new Error(`Unknown type ${type.name} ${type.kind}`);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function parseVariables(args: SchemaType[]) {
|
|
111
|
+
const parsedVariables = args.reduce(
|
|
112
|
+
(acc: VariableOptions, arg: SchemaType) => {
|
|
113
|
+
return {
|
|
114
|
+
...acc,
|
|
115
|
+
[arg.name]: getLeafArgs(arg.type, {}),
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
{},
|
|
119
|
+
);
|
|
120
|
+
return parsedVariables;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Runs a query against the currently published graphql schema,
|
|
125
|
+
* and generates a query ts file for query.
|
|
126
|
+
*/
|
|
127
|
+
async function run() {
|
|
128
|
+
console.log("Generating...");
|
|
129
|
+
|
|
130
|
+
// Fetch schema from remote
|
|
131
|
+
const res = await fetch(`https://graph.codex.io/schema/latest.json`, {
|
|
132
|
+
method: "GET",
|
|
133
|
+
});
|
|
134
|
+
const schemaJson = await res.json();
|
|
135
|
+
|
|
136
|
+
const types = schemaJson.__schema.types;
|
|
137
|
+
const mutationType = types.find(
|
|
138
|
+
(type: SchemaType) => type.name === "Mutation",
|
|
139
|
+
);
|
|
140
|
+
const queryType = types.find((type: SchemaType) => type.name === "Query");
|
|
141
|
+
const subscriptionType = types.find(
|
|
142
|
+
(type: SchemaType) => type.name === "Subscription",
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
for (const field of mutationType.fields) {
|
|
146
|
+
const args = field.args;
|
|
147
|
+
const parsedVariables = parseVariables(args);
|
|
148
|
+
const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
|
|
149
|
+
|
|
150
|
+
const mutationBuilderObject = gql.mutation({
|
|
151
|
+
operation: field.name,
|
|
152
|
+
variables: Object.keys(parsedVariables).length
|
|
153
|
+
? parsedVariables
|
|
154
|
+
: undefined,
|
|
155
|
+
fields: parsedFields.length ? parsedFields : undefined,
|
|
156
|
+
});
|
|
157
|
+
console.log(`Writing mutation: ${field.name}.graphql`);
|
|
158
|
+
const mutationsFolderPath = path.join(
|
|
159
|
+
__dirname,
|
|
160
|
+
"..",
|
|
161
|
+
"resources",
|
|
162
|
+
"generated_mutations",
|
|
163
|
+
);
|
|
164
|
+
await mkdirp(mutationsFolderPath);
|
|
165
|
+
fs.writeFileSync(
|
|
166
|
+
path.join(mutationsFolderPath, `${capitalize(field.name)}.graphql`),
|
|
167
|
+
`mutation ${capitalize(field.name)}${mutationBuilderObject.query
|
|
168
|
+
.toString()
|
|
169
|
+
.slice("mutation ".length)}`,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const field of subscriptionType.fields) {
|
|
174
|
+
const args = field.args;
|
|
175
|
+
const parsedVariables = parseVariables(args);
|
|
176
|
+
const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
|
|
177
|
+
|
|
178
|
+
const subscriptionBuilderObject = gql.subscription({
|
|
179
|
+
operation: field.name,
|
|
180
|
+
variables: Object.keys(parsedVariables).length
|
|
181
|
+
? parsedVariables
|
|
182
|
+
: undefined,
|
|
183
|
+
fields: parsedFields.length ? parsedFields : undefined,
|
|
184
|
+
});
|
|
185
|
+
console.log(`Writing subscription: ${field.name}.graphql`);
|
|
186
|
+
const subscriptionsFolderPath = path.join(
|
|
187
|
+
__dirname,
|
|
188
|
+
"..",
|
|
189
|
+
"resources",
|
|
190
|
+
"generated_subscriptions",
|
|
191
|
+
);
|
|
192
|
+
await mkdirp(subscriptionsFolderPath);
|
|
193
|
+
fs.writeFileSync(
|
|
194
|
+
path.join(subscriptionsFolderPath, `${capitalize(field.name)}.graphql`),
|
|
195
|
+
`subscription ${capitalize(field.name)}${subscriptionBuilderObject.query
|
|
196
|
+
.toString()
|
|
197
|
+
.slice("subscription ".length)}`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (const field of queryType.fields) {
|
|
202
|
+
if (field.isDeprecated) {
|
|
203
|
+
console.log("Skipping deprecated field", field.name);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const args = field.args;
|
|
208
|
+
const parsedVariables = parseVariables(args);
|
|
209
|
+
const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
|
|
210
|
+
|
|
211
|
+
const queryBuilderObject = gql.query({
|
|
212
|
+
operation: field.name,
|
|
213
|
+
variables: Object.keys(parsedVariables).length
|
|
214
|
+
? parsedVariables
|
|
215
|
+
: undefined,
|
|
216
|
+
fields: parsedFields.length ? parsedFields : undefined,
|
|
217
|
+
});
|
|
218
|
+
console.log(`Writing query: ${field.name}.graphql`);
|
|
219
|
+
|
|
220
|
+
const queriesFolderPath = path.join(
|
|
221
|
+
__dirname,
|
|
222
|
+
"..",
|
|
223
|
+
"resources",
|
|
224
|
+
"generated_queries",
|
|
225
|
+
);
|
|
226
|
+
await mkdirp(queriesFolderPath);
|
|
227
|
+
fs.writeFileSync(
|
|
228
|
+
path.join(queriesFolderPath, `${capitalize(field.name)}.graphql`),
|
|
229
|
+
`query ${capitalize(field.name)}${queryBuilderObject.query
|
|
230
|
+
.toString()
|
|
231
|
+
.slice("query ".length)}`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
run().then(() => process.exit());
|
package/src/sdk/Mutation.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT IT DIRECTLY
|
|
2
2
|
import {
|
|
3
|
+
CreateApiTokensDocument,
|
|
4
|
+
CreateApiTokensMutationVariables,
|
|
3
5
|
CreateWebhooksDocument,
|
|
4
|
-
|
|
6
|
+
CreateWebhooksMutationVariables,
|
|
7
|
+
DeleteApiTokenDocument,
|
|
8
|
+
DeleteApiTokenMutationVariables,
|
|
5
9
|
DeleteWebhooksDocument,
|
|
10
|
+
DeleteWebhooksMutationVariables,
|
|
6
11
|
} from "./generated/graphql";
|
|
7
12
|
import { Codex } from "./index";
|
|
8
13
|
|
|
9
14
|
export class Mutation {
|
|
10
15
|
constructor(private sdk: Codex) {}
|
|
11
|
-
|
|
16
|
+
deleteApiToken = async (vars: DeleteApiTokenMutationVariables) =>
|
|
17
|
+
this.sdk.mutation(DeleteApiTokenDocument, vars);
|
|
18
|
+
createWebhooks = async (vars: CreateWebhooksMutationVariables) =>
|
|
12
19
|
this.sdk.mutation(CreateWebhooksDocument, vars);
|
|
13
|
-
|
|
20
|
+
createApiTokens = async (vars: CreateApiTokensMutationVariables) =>
|
|
21
|
+
this.sdk.mutation(CreateApiTokensDocument, vars);
|
|
22
|
+
deleteWebhooks = async (vars: DeleteWebhooksMutationVariables) =>
|
|
14
23
|
this.sdk.mutation(DeleteWebhooksDocument, vars);
|
|
15
24
|
}
|