Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(custom-scalars): prefill registry with gen-linked cs #1230

Merged
merged 5 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArg(date: {})
dateArg(date: "1970-01-01T00:00:00.000Z")
}
----------------
{
Expand Down Expand Up @@ -1263,7 +1263,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgList(date: [{}, {}])
dateArgList(date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"])
}
----------------
{
Expand All @@ -1285,7 +1285,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgNonNull(date: {})
dateArgNonNull(date: "1970-01-01T00:00:00.000Z")
}
----------------
{
Expand All @@ -1310,7 +1310,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgNonNullList(date: [{}, {}])
dateArgNonNullList(
date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"]
)
}
----------------
{
Expand All @@ -1335,7 +1337,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgNonNullList(date: [null, {}])
dateArgNonNullList(date: [null, "1970-01-01T00:00:00.000Z"])
}
----------------
{
Expand All @@ -1360,7 +1362,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ar
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgNonNullListNonNull(date: [{}, {}])
dateArgNonNullListNonNull(
date: ["1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.001Z"]
)
}
----------------
{
Expand All @@ -1386,7 +1390,9 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - in
}
--------GRAPHQL DOCUMENT & VARIABLES--------
{
dateArgInputObject(input: {idRequired: "", dateRequired: {}, date: {}})
dateArgInputObject(
input: {idRequired: "", dateRequired: "1970-01-01T00:00:00.000Z", date: "1970-01-01T00:00:00.001Z"}
)
}
----------------
{
Expand Down Expand Up @@ -1415,7 +1421,7 @@ exports[`( variables: false; scalars: Date ) - Query - args - custom scalar - ne
--------GRAPHQL DOCUMENT & VARIABLES--------
{
InputObjectNested(
input: {InputObject: {idRequired: "", dateRequired: {}, date: {}}}
input: {InputObject: {idRequired: "", dateRequired: "1970-01-01T00:00:00.000Z", date: "1970-01-01T00:00:00.001Z"}}
)
}
----------------
Expand Down
1 change: 1 addition & 0 deletions src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const tester = <$Scalars extends Schema.Scalar.ScalarMap>(
),
{
sddm: schemaDrivenDataMap,
scalars: input.scalars,
operationVariables: input.variables,
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { createPrefilled } from '../../../../../../entrypoints/client.js'
import * as $$Data from './data.js'
import * as $$Scalar from './scalar.js'
import * as $$SchemaDrivenDataMap from './schema-driven-data-map.js'
export const create = createPrefilled($$Data.Name, $$SchemaDrivenDataMap.schemaDrivenDataMap, $$Data.defaultSchemaUrl)

export const create = createPrefilled(
$$Data.Name,
$$SchemaDrivenDataMap.schemaDrivenDataMap,
$$Scalar.$registry,
$$Data.defaultSchemaUrl,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@ export * from '../../../../../../types/Schema/StandardTypes/scalar.js'
//

export type Date = $$Utilities.Schema.Scalar.ScalarCodecless<'Date'>

//
//
//
//
//
//
// ==================================================================================================
// Registry
// ==================================================================================================
//
//
//
//
//
//

export const $registry = {
map: {},
} as $Registry

export type $Registry = $$Utilities.Schema.Scalar.Registry.Empty
Original file line number Diff line number Diff line change
Expand Up @@ -1669,9 +1669,7 @@ export namespace Schema {
//
//

export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Utilities.Schema.Scalar.Registry.Empty>
extends $
{
export interface Schema<$Scalars extends $$Utilities.Schema.Scalar.Registry = $$Scalar.$Registry> extends $ {
name: $$Data.Name
operationsAvailable: ['query', 'mutation']
RootUnion:
Expand Down
18 changes: 9 additions & 9 deletions src/generator/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'node:fs/promises'
import * as Path from 'node:path'
import { Graffle } from '../../entrypoints/__Graffle.js'
import { Introspection } from '../../extensions/Introspection/Introspection.js'
Expand Down Expand Up @@ -65,6 +64,10 @@ interface ConfigSchema {
}

export const createConfig = async (input: Input): Promise<Config> => {
// --- Fs ---

const fs = input.fs ?? await import(`node:fs/promises`)

// --- Output Case ---

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

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

// --- Schema ---

const schema = await createConfigSchema(cwd, sourceDirPath, input)
const schema = await createConfigSchema(fs, cwd, sourceDirPath, input)

// --- Default Schema URL ---

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

// --- Fs ---

const fs = input.fs ?? await import(`node:fs/promises`)

// --- Config ---

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

const createConfigSchema = async (
fs: Fs,
cwd: string,
sourceDirPath: string,
input: Input,
Expand All @@ -252,7 +252,7 @@ const createConfigSchema = async (
const fileOrDirPath = input.schema.dirOrFilePath
? toAbsolutePath(cwd, input.schema.dirOrFilePath)
: sourceDirPath
const isDir = await isPathToADirectory(fileOrDirPath)
const isDir = await isPathToADirectory(fs, fileOrDirPath)
sdlFilePath = isDir ? Path.join(fileOrDirPath, defaultSchemaFileName) : fileOrDirPath
sdl = await fs.readFile(sdlFilePath, `utf8`)
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/generator/configFile/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export const load = async (
}

const processInput = async (input?: string) => {
const fs = await import(`node:fs/promises`)

if (!input) {
const directoryPath = process.cwd()
const path = Path.join(directoryPath, loadDefaults.fileName)
Expand All @@ -91,7 +93,7 @@ const processInput = async (input?: string) => {

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

if (await isPathToADirectory(absolutePath)) {
if (await isPathToADirectory(fs, absolutePath)) {
const directoryPath = absolutePath
const path = Path.join(directoryPath, loadDefaults.fileName)
return extensionCandidates.map(ext => `${path}.${ext}`)
Expand Down
Loading