Skip to content

Commit 52c0d8a

Browse files
authored
feat(custom-scalars): prefill registry with gen-linked cs (#1230)
1 parent 0d4534c commit 52c0d8a

File tree

39 files changed

+687
-175
lines changed

39 files changed

+687
-175
lines changed

src/documentBuilder/SelectGraphQLMapper/__snapshots__/toGraphQL.test.ts.snap

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
12161216
}
12171217
--------GRAPHQL DOCUMENT & VARIABLES--------
12181218
{
1219-
dateArg(date: {})
1219+
dateArg(date: "1970-01-01T00:00:00.000Z")
12201220
}
12211221
----------------
12221222
{
@@ -1263,7 +1263,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
12631263
}
12641264
--------GRAPHQL DOCUMENT & VARIABLES--------
12651265
{
1266-
dateArgList(date: [{}, {}])
1266+
dateArgList(date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"])
12671267
}
12681268
----------------
12691269
{
@@ -1285,7 +1285,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
12851285
}
12861286
--------GRAPHQL DOCUMENT & VARIABLES--------
12871287
{
1288-
dateArgNonNull(date: {})
1288+
dateArgNonNull(date: "1970-01-01T00:00:00.000Z")
12891289
}
12901290
----------------
12911291
{
@@ -1310,7 +1310,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
13101310
}
13111311
--------GRAPHQL DOCUMENT & VARIABLES--------
13121312
{
1313-
dateArgNonNullList(date: [{}, {}])
1313+
dateArgNonNullList(
1314+
date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"]
1315+
)
13141316
}
13151317
----------------
13161318
{
@@ -1335,7 +1337,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
13351337
}
13361338
--------GRAPHQL DOCUMENT & VARIABLES--------
13371339
{
1338-
dateArgNonNullList(date: [null, {}])
1340+
dateArgNonNullList(date: [null, "1970-01-01T00:00:00.000Z"])
13391341
}
13401342
----------------
13411343
{
@@ -1360,7 +1362,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
13601362
}
13611363
--------GRAPHQL DOCUMENT & VARIABLES--------
13621364
{
1363-
dateArgNonNullListNonNull(date: [{}, {}])
1365+
dateArgNonNullListNonNull(
1366+
date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"]
1367+
)
13641368
}
13651369
----------------
13661370
{
@@ -1386,7 +1390,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - in
13861390
}
13871391
--------GRAPHQL DOCUMENT & VARIABLES--------
13881392
{
1389-
dateArgInputObject(input: {idRequired: "", dateRequired: {}, date: {}})
1393+
dateArgInputObject(
1394+
input: {idRequired: "", dateRequired: "1970-01-01T00:00:00.000Z", date: "1970-01-01T00:00:00.001Z"}
1395+
)
13901396
}
13911397
----------------
13921398
{
@@ -1415,7 +1421,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ne
14151421
--------GRAPHQL DOCUMENT & VARIABLES--------
14161422
{
14171423
InputObjectNested(
1418-
input: {InputObject: {idRequired: "", dateRequired: {}, date: {}}}
1424+
input: {InputObject: {idRequired: "", dateRequired: "1970-01-01T00:00:00.000Z", date: "1970-01-01T00:00:00.001Z"}}
14191425
)
14201426
}
14211427
----------------

src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const tester = <$Scalars extends Schema.Scalar.ScalarMap>(
4141
),
4242
{
4343
sddm: schemaDrivenDataMap,
44+
scalars: input.scalars,
4445
operationVariables: input.variables,
4546
},
4647
)
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import { createPrefilled } from '../../../../../../entrypoints/client.js'
22
import * as $$Data from './data.js'
3+
import * as $$Scalar from './scalar.js'
34
import * as $$SchemaDrivenDataMap from './schema-driven-data-map.js'
4-
export const create = createPrefilled($$Data.Name, $$SchemaDrivenDataMap.schemaDrivenDataMap, $$Data.defaultSchemaUrl)
5+
6+
export const create = createPrefilled(
7+
$$Data.Name,
8+
$$SchemaDrivenDataMap.schemaDrivenDataMap,
9+
$$Scalar.$registry,
10+
$$Data.defaultSchemaUrl,
11+
)

src/extensions/SchemaErrors/tests/fixture/graffle/modules/scalar.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,25 @@ export * from '../../../../../../types/Schema/StandardTypes/scalar.js'
1515
//
1616

1717
export type Date = $$Utilities.Schema.Scalar.ScalarCodecless<'Date'>
18+
19+
//
20+
//
21+
//
22+
//
23+
//
24+
//
25+
// ==================================================================================================
26+
// Registry
27+
// ==================================================================================================
28+
//
29+
//
30+
//
31+
//
32+
//
33+
//
34+
35+
export const $registry = {
36+
map: {},
37+
} as $Registry
38+
39+
export type $Registry = $$Utilities.Schema.Scalar.Registry.Empty

src/extensions/SchemaErrors/tests/fixture/graffle/modules/schema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,9 +1669,7 @@ export namespace Schema {
16691669
//
16701670
//
16711671

1672-
export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty>
1673-
extends $
1674-
{
1672+
export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Scalar.$Registry> extends $ {
16751673
name: $$Data.Name
16761674
operationsAvailable: ['query', 'mutation']
16771675
RootUnion:

src/generator/config/config.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from 'node:fs/promises'
21
import * as Path from 'node:path'
32
import { Graffle } from '../../entrypoints/__Graffle.js'
43
import { Introspection } from '../../extensions/Introspection/Introspection.js'
@@ -65,6 +64,10 @@ interface ConfigSchema {
6564
}
6665

6766
export const createConfig = async (input: Input): Promise<Config> => {
67+
// --- Fs ---
68+
69+
const fs = input.fs ?? await import(`node:fs/promises`)
70+
6871
// --- Output Case ---
6972

7073
const outputCase = input.outputCase ?? defaultOutputCase
@@ -85,7 +88,7 @@ export const createConfig = async (input: Input): Promise<Config> => {
8588
? toAbsolutePath(cwd, input.scalars)
8689
: Path.join(sourceDirPath, `scalars` + `.ts`)
8790

88-
const isCustomScalarsModuleExists = await fileExists(inputPathScalars)
91+
const isCustomScalarsModuleExists = await fileExists(fs, inputPathScalars)
8992
if (!isCustomScalarsModuleExists && input.scalars) {
9093
// dprint-ignore
9194
throw new Error(
@@ -100,7 +103,7 @@ export const createConfig = async (input: Input): Promise<Config> => {
100103

101104
// --- Schema ---
102105

103-
const schema = await createConfigSchema(cwd, sourceDirPath, input)
106+
const schema = await createConfigSchema(fs, cwd, sourceDirPath, input)
104107

105108
// --- Default Schema URL ---
106109

@@ -119,7 +122,7 @@ export const createConfig = async (input: Input): Promise<Config> => {
119122
const formattingEnabled = input.format ?? true
120123
let formatter = passthroughFormatter
121124
if (formattingEnabled) {
122-
const formatterReal = await getTypeScriptFormatter()
125+
const formatterReal = await getTypeScriptFormatter(fs)
123126
if (!formatterReal) {
124127
// todo use floggy
125128
console.log(`
@@ -171,10 +174,6 @@ To suppress this warning disable formatting in one of the following ways:
171174
: Path.join(outputDirPathRoot, `schema.graphql`)
172175
: null
173176

174-
// --- Fs ---
175-
176-
const fs = input.fs ?? await import(`node:fs/promises`)
177-
178177
// --- Config ---
179178

180179
// const customScalarsEnabled = input.customScalars ?? false
@@ -227,6 +226,7 @@ To suppress this warning disable formatting in one of the following ways:
227226
const defaultSchemaFileName = `schema.graphql`
228227

229228
const createConfigSchema = async (
229+
fs: Fs,
230230
cwd: string,
231231
sourceDirPath: string,
232232
input: Input,
@@ -252,7 +252,7 @@ const createConfigSchema = async (
252252
const fileOrDirPath = input.schema.dirOrFilePath
253253
? toAbsolutePath(cwd, input.schema.dirOrFilePath)
254254
: sourceDirPath
255-
const isDir = await isPathToADirectory(fileOrDirPath)
255+
const isDir = await isPathToADirectory(fs, fileOrDirPath)
256256
sdlFilePath = isDir ? Path.join(fileOrDirPath, defaultSchemaFileName) : fileOrDirPath
257257
sdl = await fs.readFile(sdlFilePath, `utf8`)
258258
} else {

src/generator/configFile/loader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export const load = async (
8383
}
8484

8585
const processInput = async (input?: string) => {
86+
const fs = await import(`node:fs/promises`)
87+
8688
if (!input) {
8789
const directoryPath = process.cwd()
8890
const path = Path.join(directoryPath, loadDefaults.fileName)
@@ -91,7 +93,7 @@ const processInput = async (input?: string) => {
9193

9294
const absolutePath = toAbsolutePath(process.cwd(), input)
9395

94-
if (await isPathToADirectory(absolutePath)) {
96+
if (await isPathToADirectory(fs, absolutePath)) {
9597
const directoryPath = absolutePath
9698
const path = Path.join(directoryPath, loadDefaults.fileName)
9799
return extensionCandidates.map(ext => `${path}.${ext}`)

0 commit comments

Comments
 (0)