@codex-data/sdk 1.0.37 → 1.0.39

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.
Files changed (135) hide show
  1. package/package.json +2 -3
  2. package/dist/scripts/buildSdk.d.ts +0 -2
  3. package/dist/scripts/buildSdk.d.ts.map +0 -1
  4. package/dist/scripts/buildSdk.js +0 -135
  5. package/dist/scripts/buildSdk.js.map +0 -1
  6. package/dist/scripts/generateGraphql.d.ts +0 -31
  7. package/dist/scripts/generateGraphql.d.ts.map +0 -1
  8. package/dist/scripts/generateGraphql.js +0 -224
  9. package/dist/scripts/generateGraphql.js.map +0 -1
  10. package/dist/scripts/generateNetworkConfigs.d.ts +0 -2
  11. package/dist/scripts/generateNetworkConfigs.d.ts.map +0 -1
  12. package/dist/scripts/generateNetworkConfigs.js +0 -248
  13. package/dist/scripts/generateNetworkConfigs.js.map +0 -1
  14. package/src/index.ts +0 -2
  15. package/src/resources/.keep +0 -0
  16. package/src/resources/generated_mutations/BackfillWalletAggregates.graphql +0 -6
  17. package/src/resources/generated_mutations/CreateApiTokens.graphql +0 -9
  18. package/src/resources/generated_mutations/CreateWebhooks.graphql +0 -472
  19. package/src/resources/generated_mutations/DeleteApiToken.graphql +0 -3
  20. package/src/resources/generated_mutations/DeleteWebhooks.graphql +0 -5
  21. package/src/resources/generated_queries/ApiToken.graphql +0 -9
  22. package/src/resources/generated_queries/ApiTokens.graphql +0 -9
  23. package/src/resources/generated_queries/Balances.graphql +0 -97
  24. package/src/resources/generated_queries/Blocks.graphql +0 -7
  25. package/src/resources/generated_queries/ChartUrls.graphql +0 -7
  26. package/src/resources/generated_queries/DetailedWalletStats.graphql +0 -197
  27. package/src/resources/generated_queries/FilterExchanges.graphql +0 -43
  28. package/src/resources/generated_queries/FilterNftCollections.graphql +0 -569
  29. package/src/resources/generated_queries/FilterNftParallelAssets.graphql +0 -60
  30. package/src/resources/generated_queries/FilterNftPoolCollections.graphql +0 -71
  31. package/src/resources/generated_queries/FilterNftPools.graphql +0 -124
  32. package/src/resources/generated_queries/FilterPairs.graphql +0 -448
  33. package/src/resources/generated_queries/FilterTokenWallets.graphql +0 -144
  34. package/src/resources/generated_queries/FilterTokens.graphql +0 -579
  35. package/src/resources/generated_queries/FilterWallets.graphql +0 -57
  36. package/src/resources/generated_queries/GetBars.graphql +0 -233
  37. package/src/resources/generated_queries/GetCommunityNotes.graphql +0 -140
  38. package/src/resources/generated_queries/GetDetailedNftStats.graphql +0 -831
  39. package/src/resources/generated_queries/GetDetailedPairStats.graphql +0 -991
  40. package/src/resources/generated_queries/GetDetailedPairsStats.graphql +0 -975
  41. package/src/resources/generated_queries/GetEventLabels.graphql +0 -35
  42. package/src/resources/generated_queries/GetExchanges.graphql +0 -12
  43. package/src/resources/generated_queries/GetNetworkConfigs.graphql +0 -129
  44. package/src/resources/generated_queries/GetNetworkStats.graphql +0 -20
  45. package/src/resources/generated_queries/GetNetworkStatus.graphql +0 -8
  46. package/src/resources/generated_queries/GetNetworks.graphql +0 -7
  47. package/src/resources/generated_queries/GetNftAssets.graphql +0 -59
  48. package/src/resources/generated_queries/GetNftCollectionMetadata.graphql +0 -75
  49. package/src/resources/generated_queries/GetNftContracts.graphql +0 -39
  50. package/src/resources/generated_queries/GetNftEvents.graphql +0 -100
  51. package/src/resources/generated_queries/GetNftPool.graphql +0 -74
  52. package/src/resources/generated_queries/GetNftPoolCollection.graphql +0 -33
  53. package/src/resources/generated_queries/GetNftPoolCollectionsByExchange.graphql +0 -38
  54. package/src/resources/generated_queries/GetNftPoolEvents.graphql +0 -416
  55. package/src/resources/generated_queries/GetNftPoolStats.graphql +0 -40
  56. package/src/resources/generated_queries/GetNftPoolsByCollectionAndExchange.graphql +0 -89
  57. package/src/resources/generated_queries/GetNftPoolsByOwner.graphql +0 -89
  58. package/src/resources/generated_queries/GetParallelCardChanges.graphql +0 -57
  59. package/src/resources/generated_queries/GetPrimePoolAssets.graphql +0 -32
  60. package/src/resources/generated_queries/GetPrimePoolEvents.graphql +0 -156
  61. package/src/resources/generated_queries/GetPrimePools.graphql +0 -62
  62. package/src/resources/generated_queries/GetSymbol.graphql +0 -11
  63. package/src/resources/generated_queries/GetTokenBars.graphql +0 -121
  64. package/src/resources/generated_queries/GetTokenEvents.graphql +0 -102
  65. package/src/resources/generated_queries/GetTokenEventsForMaker.graphql +0 -102
  66. package/src/resources/generated_queries/GetTokenPrices.graphql +0 -9
  67. package/src/resources/generated_queries/GetWebhooks.graphql +0 -134
  68. package/src/resources/generated_queries/Holders.graphql +0 -100
  69. package/src/resources/generated_queries/LiquidityLocks.graphql +0 -32
  70. package/src/resources/generated_queries/LiquidityMetadata.graphql +0 -17
  71. package/src/resources/generated_queries/LiquidityMetadataByToken.graphql +0 -19
  72. package/src/resources/generated_queries/ListPairsForToken.graphql +0 -194
  73. package/src/resources/generated_queries/ListPairsWithMetadataForToken.graphql +0 -375
  74. package/src/resources/generated_queries/NftHolders.graphql +0 -12
  75. package/src/resources/generated_queries/PairMetadata.graphql +0 -234
  76. package/src/resources/generated_queries/PrimeHolders.graphql +0 -98
  77. package/src/resources/generated_queries/SearchNfts.graphql +0 -35
  78. package/src/resources/generated_queries/Token.graphql +0 -82
  79. package/src/resources/generated_queries/TokenLifecycleEvents.graphql +0 -34
  80. package/src/resources/generated_queries/TokenSparklines.graphql +0 -11
  81. package/src/resources/generated_queries/TokenTopTraders.graphql +0 -26
  82. package/src/resources/generated_queries/Tokens.graphql +0 -82
  83. package/src/resources/generated_queries/Top10HoldersPercent.graphql +0 -3
  84. package/src/resources/generated_queries/WalletAggregateBackfillState.graphql +0 -6
  85. package/src/resources/generated_queries/WalletChart.graphql +0 -20
  86. package/src/resources/generated_queries/WalletNftCollectionAssets.graphql +0 -11
  87. package/src/resources/generated_queries/WalletNftCollections.graphql +0 -10
  88. package/src/resources/generated_subscriptions/OnBalanceUpdated.graphql +0 -94
  89. package/src/resources/generated_subscriptions/OnBarsUpdated.graphql +0 -547
  90. package/src/resources/generated_subscriptions/OnDetailedStatsUpdated.graphql +0 -325
  91. package/src/resources/generated_subscriptions/OnEventLabelCreated.graphql +0 -22
  92. package/src/resources/generated_subscriptions/OnEventsCreated.graphql +0 -105
  93. package/src/resources/generated_subscriptions/OnEventsCreatedByMaker.graphql +0 -92
  94. package/src/resources/generated_subscriptions/OnHoldersUpdated.graphql +0 -100
  95. package/src/resources/generated_subscriptions/OnLatestPairUpdated.graphql +0 -42
  96. package/src/resources/generated_subscriptions/OnLatestTokens.graphql +0 -37
  97. package/src/resources/generated_subscriptions/OnLaunchpadTokenEvent.graphql +0 -104
  98. package/src/resources/generated_subscriptions/OnLaunchpadTokenEventBatch.graphql +0 -96
  99. package/src/resources/generated_subscriptions/OnNftAssetsCreated.graphql +0 -42
  100. package/src/resources/generated_subscriptions/OnNftEventsCreated.graphql +0 -82
  101. package/src/resources/generated_subscriptions/OnNftPoolEventsCreated.graphql +0 -412
  102. package/src/resources/generated_subscriptions/OnPairMetadataUpdated.graphql +0 -234
  103. package/src/resources/generated_subscriptions/OnPriceUpdated.graphql +0 -17
  104. package/src/resources/generated_subscriptions/OnPricesUpdated.graphql +0 -9
  105. package/src/resources/generated_subscriptions/OnTokenBarsUpdated.graphql +0 -545
  106. package/src/resources/generated_subscriptions/OnTokenEventsCreated.graphql +0 -92
  107. package/src/resources/generated_subscriptions/OnTokenLifecycleEventsCreated.graphql +0 -30
  108. package/src/resources/generated_subscriptions/OnUnconfirmedBarsUpdated.graphql +0 -115
  109. package/src/resources/generated_subscriptions/OnUnconfirmedEventsCreated.graphql +0 -50
  110. package/src/resources/generated_subscriptions/OnUnconfirmedEventsCreatedByMaker.graphql +0 -41
  111. package/src/resources/graphql.schema.json +0 -63699
  112. package/src/resources/graphql.ts +0 -10477
  113. package/src/resources/mutations_override/CreateWebhooks.graphql +0 -472
  114. package/src/resources/networkConfigs.json +0 -3757
  115. package/src/resources/queries_override/FilterTokenWallets.graphql +0 -144
  116. package/src/resources/queries_override/GetEventLabels.graphql +0 -35
  117. package/src/resources/queries_override/GetNetworkConfigs.graphql +0 -129
  118. package/src/resources/queries_override/GetWebhooks.graphql +0 -134
  119. package/src/resources/schema.graphql +0 -9972
  120. package/src/resources/subscriptions_override/OnEventLabelCreated.graphql +0 -22
  121. package/src/resources/subscriptions_override/OnLaunchpadTokenEventBatch.graphql +0 -96
  122. package/src/scripts/buildSdk.ts +0 -173
  123. package/src/scripts/generateGraphql.ts +0 -305
  124. package/src/scripts/generateNetworkConfigs.ts +0 -250
  125. package/src/sdk/Mutation.ts +0 -29
  126. package/src/sdk/Query.ts +0 -285
  127. package/src/sdk/Subscribe.ts +0 -465
  128. package/src/sdk/generated/fragment-masking.ts +0 -87
  129. package/src/sdk/generated/gql.ts +0 -610
  130. package/src/sdk/generated/graphql.ts +0 -11417
  131. package/src/sdk/generated/index.ts +0 -2
  132. package/src/sdk/graphql/GetPairEvents.graphql +0 -71
  133. package/src/sdk/index.test.ts +0 -454
  134. package/src/sdk/index.ts +0 -239
  135. package/src/sdk/invariant.ts +0 -34
@@ -1,22 +0,0 @@
1
- subscription OnEventLabelCreated($id: String) {
2
- onEventLabelCreated(id: $id) {
3
- data {
4
- ... on FrontRunLabelData {
5
- index
6
- token0DrainedAmount
7
- token1DrainedAmount
8
- }
9
- ... on SandwichedLabelData {
10
- token0DrainedAmountSandwich: token0DrainedAmount
11
- token1DrainedAmountSandwich: token1DrainedAmount
12
- }
13
- }
14
- id
15
- label
16
- logIndex
17
- networkId
18
- timestamp
19
- transactionHash
20
- transactionIndex
21
- }
22
- }
@@ -1,96 +0,0 @@
1
- subscription OnLaunchpadTokenEventBatch(
2
- $input: OnLaunchpadTokenEventBatchInput
3
- ) {
4
- onLaunchpadTokenEventBatch(input: $input) {
5
- address
6
- buyCount1
7
- eventType
8
- holders
9
- marketCap
10
- networkId
11
- price
12
- protocol
13
- sellCount1
14
- launchpadName
15
- token {
16
- address
17
- cmcId
18
- createBlockNumber
19
- createTransactionHash
20
- createdAt
21
- creatorAddress
22
- decimals
23
- exchanges {
24
- address
25
- color
26
- exchangeVersion
27
- iconUrl
28
- id
29
- name
30
- networkId
31
- tradeUrl
32
- }
33
- freezable
34
- id
35
- info {
36
- address
37
- circulatingSupply
38
- cmcId
39
- description
40
- id
41
- imageBannerUrl
42
- imageLargeUrl
43
- imageSmallUrl
44
- imageThumbUrl
45
- isScam
46
- name
47
- networkId
48
- symbol
49
- totalSupply
50
- }
51
- isScam
52
- launchpad {
53
- completed
54
- completedAt
55
- completedSlot
56
- graduationPercent
57
- launchpadProtocol
58
- migrated
59
- migratedAt
60
- migratedPoolAddress
61
- migratedSlot
62
- name
63
- launchpadName
64
- poolAddress
65
- }
66
- mintable
67
- name
68
- networkId
69
- socialLinks {
70
- bitcointalk
71
- blog
72
- coingecko
73
- coinmarketcap
74
- discord
75
- email
76
- facebook
77
- github
78
- instagram
79
- linkedin
80
- reddit
81
- slack
82
- telegram
83
- twitch
84
- twitter
85
- website
86
- wechat
87
- whitepaper
88
- youtube
89
- }
90
- symbol
91
- }
92
- transactions1
93
- volume1
94
- liquidity
95
- }
96
- }
@@ -1,173 +0,0 @@
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)} = (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());
@@ -1,305 +0,0 @@
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
- possibleTypes?: SchemaType[];
29
- fields?: SchemaType[];
30
- };
31
-
32
- type Fields = Array<string | { [key: string]: Fields }>;
33
-
34
- function capitalize(str: string) {
35
- return str.charAt(0).toUpperCase() + str.slice(1);
36
- }
37
-
38
- export const getLeafType = (
39
- type: SchemaTypeDefinition,
40
- allTypes: SchemaType[],
41
- result: Fields,
42
- currentName: string,
43
- level = 0,
44
- ): Fields => {
45
- if (level > 8 || !type?.kind || type.isDeprecated) 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 (type.kind === "UNION") {
52
- // Find all the possible types
53
- const possibleTypes = allTypes.find(
54
- (t) => t.name === type.name,
55
- )?.possibleTypes;
56
-
57
- // For each of the possible types, treat it as a sub object with a set of fields
58
- const possibleTypeLeaves = possibleTypes
59
- ?.map((f: SchemaType) => {
60
- const resolvedType = allTypes.find(
61
- (t) => t.name === f.name,
62
- ) as unknown as SchemaTypeDefinition;
63
- return getLeafType(
64
- resolvedType,
65
- allTypes,
66
- [],
67
- `... on ${f.name}`,
68
- level + 1,
69
- );
70
- })
71
- .flat();
72
-
73
- if (!possibleTypeLeaves?.length) {
74
- console.log("No possible types for union", type);
75
- throw new Error(`No possible types for union type ${currentName}`);
76
- }
77
-
78
- return [...result, ...[{ [currentName]: possibleTypeLeaves }]];
79
- }
80
-
81
- // If it's an object resolve it.
82
- if (type.kind === "OBJECT") {
83
- // For each of the fields of the subtype, resolve them
84
- const subType = allTypes.find((t) => t.name === type.name);
85
- const subTypeLeaves = (subType?.fields ?? [])
86
- .filter((t) => !t.isDeprecated)
87
- .map((f: SchemaType) =>
88
- getLeafType(f.type, allTypes, [], f.name, level + 1),
89
- )
90
- .flat();
91
- return [
92
- ...result,
93
- ...(level === 0 ? subTypeLeaves : [{ [currentName]: subTypeLeaves }]),
94
- ];
95
- }
96
-
97
- // If it's a list, resolve the first object type
98
- if (type.kind === "LIST")
99
- return getLeafType(type.ofType!, allTypes, [...result], currentName, level);
100
-
101
- // If it's required, resolve the first object type
102
- if (type.kind === "NON_NULL")
103
- return getLeafType(type.ofType!, allTypes, [...result], currentName, level);
104
-
105
- throw new Error(`Unknown type ${type.name} ${type.kind}`);
106
- };
107
-
108
- export const getLeafArgs = (
109
- type: SchemaTypeDefinition,
110
- result: VariableOptions,
111
- ): VariableOptions => {
112
- if (
113
- type.kind === "NON_NULL" &&
114
- ["INPUT_OBJECT", "SCALAR", "OBJECT", "ENUM"].includes(
115
- type.ofType?.kind as string,
116
- )
117
- )
118
- return { ...result, type: `${type.ofType!.name!}!` };
119
-
120
- // If it's a scalar, return the name
121
- if (
122
- type.kind === "SCALAR" ||
123
- type.kind === "OBJECT" ||
124
- type.kind === "ENUM" ||
125
- type.kind === "INPUT_OBJECT"
126
- )
127
- return { ...result, type: type.name!, value: null };
128
-
129
- // If it's a list, resolve the first object type
130
- if (type.kind === "LIST")
131
- return getLeafArgs(type.ofType!, { ...result, list: true });
132
-
133
- // If it's required, resolve the first object type
134
- if (type.kind === "NON_NULL")
135
- return getLeafArgs(type.ofType!, { ...result, required: true });
136
-
137
- throw new Error(`Unknown type ${type.name} ${type.kind}`);
138
- };
139
-
140
- export function parseVariables(args: SchemaType[]) {
141
- const parsedVariables = args.reduce(
142
- (acc: VariableOptions, arg: SchemaType) => {
143
- return {
144
- ...acc,
145
- [arg.name]: getLeafArgs(arg.type, {}),
146
- };
147
- },
148
- {},
149
- );
150
- return parsedVariables;
151
- }
152
-
153
- /**
154
- * Runs a query against the currently published graphql schema,
155
- * and generates a query ts file for query.
156
- */
157
- async function run() {
158
- console.log("Generating...");
159
-
160
- // Fetch schema from remote
161
- const res = await fetch(`https://graph.codex.io/schema/latest.json`, {
162
- method: "GET",
163
- });
164
- const schemaJson = await res.json();
165
-
166
- const types = schemaJson.__schema.types;
167
- const mutationType = types.find(
168
- (type: SchemaType) => type.name === "Mutation",
169
- );
170
- const queryType = types.find((type: SchemaType) => type.name === "Query");
171
- const subscriptionType = types.find(
172
- (type: SchemaType) => type.name === "Subscription",
173
- );
174
-
175
- for (const field of mutationType.fields) {
176
- const args = field.args;
177
- const parsedVariables = parseVariables(args);
178
- const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
179
-
180
- const mutationBuilderObject = gql.mutation({
181
- operation: field.name,
182
- variables: Object.keys(parsedVariables).length
183
- ? parsedVariables
184
- : undefined,
185
- fields: parsedFields.length ? parsedFields : undefined,
186
- });
187
- console.log(`Writing mutation: ${field.name}.graphql`);
188
- const mutationsFolderPath = path.join(
189
- __dirname,
190
- "..",
191
- "resources",
192
- "generated_mutations",
193
- );
194
- await mkdirp(mutationsFolderPath);
195
-
196
- const overridePath = path.join(
197
- __dirname,
198
- "..",
199
- "resources",
200
- "mutations_override",
201
- );
202
- const filename = `${capitalize(field.name)}.graphql`;
203
- const filePath = path.join(mutationsFolderPath, filename);
204
-
205
- // If we have an override, use it.
206
- if (fs.existsSync(path.join(overridePath, filename)))
207
- fs.copyFileSync(path.join(overridePath, filename), filePath);
208
- else
209
- fs.writeFileSync(
210
- filePath,
211
- `mutation ${capitalize(field.name)}${mutationBuilderObject.query
212
- .toString()
213
- .slice("mutation ".length)}`,
214
- );
215
- }
216
-
217
- for (const field of subscriptionType.fields) {
218
- const args = field.args;
219
- const parsedVariables = parseVariables(args) ?? {};
220
- const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
221
-
222
- const subscriptionBuilderObject = gql.subscription({
223
- operation: field.name,
224
- variables: parsedVariables,
225
- fields: parsedFields.length ? parsedFields : undefined,
226
- });
227
- console.log(`Writing subscription: ${field.name}.graphql`);
228
- const subscriptionsFolderPath = path.join(
229
- __dirname,
230
- "..",
231
- "resources",
232
- "generated_subscriptions",
233
- );
234
- await mkdirp(subscriptionsFolderPath);
235
-
236
- const overridePath = path.join(
237
- __dirname,
238
- "..",
239
- "resources",
240
- "subscriptions_override",
241
- );
242
- const filename = `${capitalize(field.name)}.graphql`;
243
- const subPath = path.join(subscriptionsFolderPath, filename);
244
- // If we have an override, use it.
245
- if (fs.existsSync(path.join(overridePath, filename)))
246
- fs.copyFileSync(path.join(overridePath, filename), subPath);
247
- else
248
- fs.writeFileSync(
249
- subPath,
250
- `subscription ${capitalize(field.name)}${subscriptionBuilderObject.query
251
- .toString()
252
- .slice("subscription ".length)}`,
253
- );
254
- }
255
-
256
- // Write queries
257
- for (const field of queryType.fields) {
258
- if (field.isDeprecated) {
259
- console.log("Skipping deprecated field", field.name);
260
- continue;
261
- }
262
-
263
- const args = field.args;
264
- const parsedVariables = parseVariables(args);
265
- const parsedFields = getLeafType(field.type, types, [], "").filter(Boolean);
266
-
267
- const queryBuilderObject = gql.query({
268
- operation: field.name,
269
- variables: Object.keys(parsedVariables).length
270
- ? parsedVariables
271
- : undefined,
272
- fields: parsedFields.length ? parsedFields : undefined,
273
- });
274
- console.log(`Writing query: ${field.name}.graphql`);
275
-
276
- const queriesFolderPath = path.join(
277
- __dirname,
278
- "..",
279
- "resources",
280
- "generated_queries",
281
- );
282
- await mkdirp(queriesFolderPath);
283
-
284
- const overridePath = path.join(
285
- __dirname,
286
- "..",
287
- "resources",
288
- "queries_override",
289
- );
290
- const queryFileName = `${capitalize(field.name)}.graphql`;
291
- const queryPath = path.join(queriesFolderPath, queryFileName);
292
- // If we have an override, use it.
293
- if (fs.existsSync(path.join(overridePath, queryFileName)))
294
- fs.copyFileSync(path.join(overridePath, queryFileName), queryPath);
295
- else
296
- fs.writeFileSync(
297
- queryPath,
298
- `query ${capitalize(field.name)}${queryBuilderObject.query
299
- .toString()
300
- .slice("query ".length)}`,
301
- );
302
- }
303
- }
304
-
305
- run().then(() => process.exit());