houdini 0.17.9 → 0.17.10

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 (121) hide show
  1. package/README.md +33 -0
  2. package/build/cmd-cjs/index.js +2 -2
  3. package/build/cmd-esm/index.js +2 -2
  4. package/package.json +16 -1
  5. package/.turbo/turbo-compile.log +0 -5
  6. package/.turbo/turbo-typedefs.log +0 -5
  7. package/CHANGELOG.md +0 -377
  8. package/src/cmd/generate.ts +0 -54
  9. package/src/cmd/index.ts +0 -60
  10. package/src/cmd/init.ts +0 -637
  11. package/src/cmd/pullSchema.ts +0 -40
  12. package/src/codegen/generators/artifacts/artifacts.test.ts +0 -3246
  13. package/src/codegen/generators/artifacts/fieldKey.ts +0 -60
  14. package/src/codegen/generators/artifacts/index.ts +0 -330
  15. package/src/codegen/generators/artifacts/indexFile.ts +0 -24
  16. package/src/codegen/generators/artifacts/inputs.ts +0 -81
  17. package/src/codegen/generators/artifacts/operations.ts +0 -281
  18. package/src/codegen/generators/artifacts/pagination.test.ts +0 -664
  19. package/src/codegen/generators/artifacts/policy.test.ts +0 -298
  20. package/src/codegen/generators/artifacts/selection.ts +0 -208
  21. package/src/codegen/generators/artifacts/utils.test.ts +0 -118
  22. package/src/codegen/generators/artifacts/utils.ts +0 -108
  23. package/src/codegen/generators/definitions/enums.test.ts +0 -61
  24. package/src/codegen/generators/definitions/enums.ts +0 -68
  25. package/src/codegen/generators/definitions/index.ts +0 -11
  26. package/src/codegen/generators/definitions/schema.test.ts +0 -236
  27. package/src/codegen/generators/index.ts +0 -6
  28. package/src/codegen/generators/indexFile/index.ts +0 -63
  29. package/src/codegen/generators/indexFile/indexFile.test.ts +0 -72
  30. package/src/codegen/generators/persistedQueries/index.ts +0 -55
  31. package/src/codegen/generators/persistedQueries/persistedQuery.test.ts +0 -26
  32. package/src/codegen/generators/runtime/index.test.ts +0 -74
  33. package/src/codegen/generators/runtime/index.ts +0 -64
  34. package/src/codegen/generators/runtime/runtime.test.ts +0 -25
  35. package/src/codegen/generators/typescript/addReferencedInputTypes.ts +0 -77
  36. package/src/codegen/generators/typescript/index.ts +0 -412
  37. package/src/codegen/generators/typescript/inlineType.ts +0 -409
  38. package/src/codegen/generators/typescript/typeReference.ts +0 -44
  39. package/src/codegen/generators/typescript/types.ts +0 -81
  40. package/src/codegen/generators/typescript/typescript.test.ts +0 -1434
  41. package/src/codegen/index.ts +0 -406
  42. package/src/codegen/transforms/addID.test.ts +0 -93
  43. package/src/codegen/transforms/addID.ts +0 -86
  44. package/src/codegen/transforms/composeQueries.test.ts +0 -50
  45. package/src/codegen/transforms/composeQueries.ts +0 -154
  46. package/src/codegen/transforms/fragmentVariables.test.ts +0 -636
  47. package/src/codegen/transforms/fragmentVariables.ts +0 -417
  48. package/src/codegen/transforms/index.ts +0 -7
  49. package/src/codegen/transforms/list.ts +0 -484
  50. package/src/codegen/transforms/lists.test.ts +0 -530
  51. package/src/codegen/transforms/paginate.test.ts +0 -1528
  52. package/src/codegen/transforms/paginate.ts +0 -770
  53. package/src/codegen/transforms/schema.test.ts +0 -136
  54. package/src/codegen/transforms/schema.ts +0 -109
  55. package/src/codegen/transforms/typename.test.ts +0 -125
  56. package/src/codegen/transforms/typename.ts +0 -55
  57. package/src/codegen/utils/commonjs.ts +0 -26
  58. package/src/codegen/utils/flattenSelections.ts +0 -179
  59. package/src/codegen/utils/graphql.test.ts +0 -35
  60. package/src/codegen/utils/graphql.ts +0 -79
  61. package/src/codegen/utils/index.ts +0 -5
  62. package/src/codegen/utils/moduleExport.ts +0 -27
  63. package/src/codegen/utils/murmur.ts +0 -79
  64. package/src/codegen/validators/index.ts +0 -4
  65. package/src/codegen/validators/noIDAlias.test.ts +0 -71
  66. package/src/codegen/validators/noIDAlias.ts +0 -39
  67. package/src/codegen/validators/plugins.ts +0 -25
  68. package/src/codegen/validators/typeCheck.test.ts +0 -960
  69. package/src/codegen/validators/typeCheck.ts +0 -1086
  70. package/src/codegen/validators/uniqueNames.test.ts +0 -59
  71. package/src/codegen/validators/uniqueNames.ts +0 -39
  72. package/src/lib/cleanupFiles.ts +0 -20
  73. package/src/lib/config.test.ts +0 -13
  74. package/src/lib/config.ts +0 -954
  75. package/src/lib/constants.ts +0 -11
  76. package/src/lib/error.ts +0 -24
  77. package/src/lib/fs.ts +0 -285
  78. package/src/lib/graphql.test.ts +0 -211
  79. package/src/lib/graphql.ts +0 -200
  80. package/src/lib/imports.ts +0 -82
  81. package/src/lib/index.ts +0 -17
  82. package/src/lib/introspection.ts +0 -39
  83. package/src/lib/parse.test.ts +0 -75
  84. package/src/lib/parse.ts +0 -23
  85. package/src/lib/path.ts +0 -49
  86. package/src/lib/pipeline.ts +0 -17
  87. package/src/lib/types.ts +0 -34
  88. package/src/lib/walk.ts +0 -104
  89. package/src/runtime/cache/cache.ts +0 -1026
  90. package/src/runtime/cache/gc.ts +0 -56
  91. package/src/runtime/cache/index.ts +0 -3
  92. package/src/runtime/cache/lists.ts +0 -516
  93. package/src/runtime/cache/storage.ts +0 -574
  94. package/src/runtime/cache/stuff.ts +0 -77
  95. package/src/runtime/cache/subscription.ts +0 -329
  96. package/src/runtime/cache/tests/availability.test.ts +0 -408
  97. package/src/runtime/cache/tests/gc.test.ts +0 -319
  98. package/src/runtime/cache/tests/keys.test.ts +0 -36
  99. package/src/runtime/cache/tests/list.test.ts +0 -3854
  100. package/src/runtime/cache/tests/readwrite.test.ts +0 -1201
  101. package/src/runtime/cache/tests/scalars.test.ts +0 -218
  102. package/src/runtime/cache/tests/storage.test.ts +0 -426
  103. package/src/runtime/cache/tests/subscriptions.test.ts +0 -1757
  104. package/src/runtime/index.ts +0 -29
  105. package/src/runtime/lib/config.ts +0 -211
  106. package/src/runtime/lib/constants.ts +0 -17
  107. package/src/runtime/lib/deepEquals.ts +0 -32
  108. package/src/runtime/lib/errors.ts +0 -8
  109. package/src/runtime/lib/index.ts +0 -8
  110. package/src/runtime/lib/log.ts +0 -69
  111. package/src/runtime/lib/network.ts +0 -303
  112. package/src/runtime/lib/networkUtils.ts +0 -151
  113. package/src/runtime/lib/scalars.test.ts +0 -877
  114. package/src/runtime/lib/scalars.ts +0 -195
  115. package/src/runtime/lib/types.ts +0 -195
  116. package/src/test/index.ts +0 -294
  117. package/src/vite/ast.ts +0 -107
  118. package/src/vite/houdini.ts +0 -113
  119. package/src/vite/imports.ts +0 -129
  120. package/src/vite/index.ts +0 -55
  121. package/src/vite/schema.ts +0 -80
package/src/vite/ast.ts DELETED
@@ -1,107 +0,0 @@
1
- import * as recast from 'recast'
2
-
3
- type Statement = recast.types.namedTypes.Statement
4
- type Program = recast.types.namedTypes.Program
5
- type ExportNamedDeclaration = recast.types.namedTypes.ExportNamedDeclaration
6
- type FunctionDeclaration = recast.types.namedTypes.FunctionDeclaration
7
- type VariableDeclaration = recast.types.namedTypes.VariableDeclaration
8
- type Identifier = recast.types.namedTypes.Identifier
9
- type ArrowFunctionExpression = recast.types.namedTypes.ArrowFunctionExpression
10
- type FunctionExpression = recast.types.namedTypes.FunctionExpression
11
-
12
- export function find_insert_index(script: Program) {
13
- let insert_index = script.body.findIndex((statement) => {
14
- return statement.type !== 'ImportDeclaration'
15
- })
16
-
17
- // if we didn't find one, make sure we add stuff at the end of the file
18
- if (insert_index === -1) {
19
- insert_index = script.body.length
20
- }
21
-
22
- return insert_index
23
- }
24
-
25
- export function find_exported_fn(
26
- body: Statement[],
27
- name: string
28
- ): FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | null {
29
- for (const statement of body) {
30
- if (statement.type !== 'ExportNamedDeclaration') {
31
- continue
32
- }
33
-
34
- const exportDeclaration = statement as ExportNamedDeclaration
35
-
36
- // if the exported thing is a function it could be what we're looking for
37
- if (exportDeclaration.declaration?.type === 'FunctionDeclaration') {
38
- const value = exportDeclaration.declaration as FunctionDeclaration
39
- if (value.id?.name === name) {
40
- return exportDeclaration.declaration
41
- }
42
- }
43
-
44
- // we also need to find exported variables that are functions or arrow functions
45
- else if (exportDeclaration.declaration?.type === 'VariableDeclaration') {
46
- const value = exportDeclaration.declaration as VariableDeclaration
47
-
48
- // make sure that the declared value has a matching name
49
- if (
50
- value.declarations.length !== 1 ||
51
- value.declarations[0].type !== 'VariableDeclarator' ||
52
- value.declarations[0].id.type !== 'Identifier' ||
53
- value.declarations[0].id.name !== name
54
- ) {
55
- continue
56
- }
57
-
58
- // we only care about this exported thing if it's a function or arrow function
59
- const declaration = value.declarations[0]
60
-
61
- if (
62
- declaration.init?.type === 'FunctionExpression' ||
63
- declaration.init?.type === 'ArrowFunctionExpression'
64
- ) {
65
- return declaration.init
66
- }
67
- }
68
- // it wasn't something we care about, move along
69
- else {
70
- continue
71
- }
72
- }
73
- const exported = body.find(
74
- (expression) =>
75
- expression.type === 'ExportNamedDeclaration' &&
76
- (((expression as ExportNamedDeclaration).declaration?.type === 'FunctionDeclaration' &&
77
- ((expression as ExportNamedDeclaration).declaration as FunctionDeclaration).id
78
- ?.name === name) ||
79
- ((expression as ExportNamedDeclaration).declaration?.type ===
80
- 'VariableDeclaration' &&
81
- ((expression as ExportNamedDeclaration).declaration as VariableDeclaration)
82
- .declarations.length === 1 &&
83
- ((expression as ExportNamedDeclaration).declaration as VariableDeclaration)
84
- .declarations[0].type === 'Identifier' &&
85
- (
86
- ((expression as ExportNamedDeclaration).declaration as VariableDeclaration)
87
- .declarations[0] as Identifier
88
- ).name === name))
89
- ) as ExportNamedDeclaration
90
- if (!exported) {
91
- return null
92
- }
93
-
94
- return exported.declaration as FunctionDeclaration
95
- }
96
-
97
- export function find_exported_id(program: Program, name: string) {
98
- return program.body.find<ExportNamedDeclaration>(
99
- (statement): statement is ExportNamedDeclaration =>
100
- statement.type === 'ExportNamedDeclaration' &&
101
- statement.declaration?.type === 'VariableDeclaration' &&
102
- statement.declaration.declarations.length === 1 &&
103
- statement.declaration.declarations[0].type === 'VariableDeclarator' &&
104
- statement.declaration.declarations[0].id.type === 'Identifier' &&
105
- statement.declaration.declarations[0].id.name === name
106
- )
107
- }
@@ -1,113 +0,0 @@
1
- import type { Plugin as VitePlugin } from 'vite'
2
-
3
- import generate from '../codegen'
4
- import { path, Config, getConfig, PluginConfig, formatErrors } from '../lib'
5
-
6
- let config: Config
7
-
8
- export default function Plugin(opts: PluginConfig = {}): VitePlugin {
9
- return {
10
- name: 'houdini',
11
-
12
- // houdini will always act as a "meta framework" and process the user's code before it
13
- // is processed by the user's library-specific plugins.
14
- enforce: 'pre',
15
-
16
- // add watch-and-run to their vite config
17
- async config(viteConfig) {
18
- config = await getConfig(opts)
19
-
20
- return {
21
- server: {
22
- ...viteConfig.server,
23
- fs: {
24
- ...viteConfig.server?.fs,
25
- allow: ['.'].concat(viteConfig.server?.fs?.allow || []),
26
- },
27
- },
28
- }
29
- },
30
-
31
- // when the build starts, we need to make sure to generate
32
- async buildStart() {
33
- try {
34
- await generate(config)
35
- } catch (e) {
36
- formatErrors(e)
37
- }
38
- },
39
-
40
- // transform the user's code
41
- async transform(code, filepath) {
42
- // everything internal to houdini should assume posix paths
43
- filepath = path.posixify(filepath)
44
-
45
- if (filepath.startsWith('/src/')) {
46
- filepath = path.join(process.cwd(), filepath)
47
- }
48
-
49
- // if the file is not in our configured source path, we need to ignore it
50
- if (!config.includeFile(filepath)) {
51
- return
52
- }
53
-
54
- // bundle up the contextual stuff
55
- const ctx: TransformPage = {
56
- content: code,
57
- watch_file: this.addWatchFile,
58
- config: config,
59
- filepath,
60
- }
61
-
62
- // run the plugin pipeline
63
- for (const plugin of config.plugins) {
64
- if (!plugin.transform_file) {
65
- continue
66
- }
67
- const { code } = await plugin.transform_file(ctx)
68
- ctx.content = code
69
- }
70
-
71
- return { code: ctx.content }
72
- },
73
-
74
- async load(id, opts, ...rest) {
75
- for (const plugin of config.plugins) {
76
- if (typeof plugin.vite?.load !== 'function') {
77
- continue
78
- }
79
-
80
- const result = await plugin.vite!.load.call(this, id, { ...opts, config }, ...rest)
81
- if (result) {
82
- return result
83
- }
84
- }
85
- },
86
-
87
- async resolveId(id, two, opts, ...rest) {
88
- for (const plugin of config.plugins) {
89
- if (typeof plugin.vite?.resolveId !== 'function') {
90
- continue
91
- }
92
-
93
- const result = await plugin.vite!.resolveId.call(
94
- this,
95
- id,
96
- two,
97
- { ...opts, config },
98
- ...rest
99
- )
100
- if (result) {
101
- return result
102
- }
103
- }
104
- },
105
- }
106
- }
107
-
108
- export interface TransformPage {
109
- config: Config
110
- content: string
111
- filepath: string
112
- watch_file: (path: string) => void
113
- }
@@ -1,129 +0,0 @@
1
- import * as recast from 'recast'
2
-
3
- import { Config } from '../lib/config'
4
- import { Script } from '../lib/types'
5
- import { TransformPage } from './houdini'
6
-
7
- const AST = recast.types.builders
8
-
9
- type Identifier = recast.types.namedTypes.Identifier
10
- type ImportDeclaration = recast.types.namedTypes.ImportDeclaration
11
-
12
- export function ensure_imports(args: {
13
- config: Config
14
- script: Script
15
- import?: string
16
- as?: never
17
- sourceModule: string
18
- importKind?: 'value' | 'type'
19
- }): { ids: Identifier; added: number }
20
- export function ensure_imports(args: {
21
- config: Config
22
- script: Script
23
- import?: string[]
24
- as?: string[]
25
- sourceModule: string
26
- importKind?: 'value' | 'type'
27
- }): { ids: Identifier[]; added: number }
28
- export function ensure_imports({
29
- config,
30
- script,
31
- import: importID,
32
- sourceModule,
33
- importKind,
34
- as,
35
- }: {
36
- config: Config
37
- script: Script
38
- import?: string[] | string
39
- as?: string[]
40
- sourceModule: string
41
- importKind?: 'value' | 'type'
42
- }): { ids: Identifier[] | Identifier; added: number } {
43
- // if there is no import, we can simplify the logic, just look for something with a matching source
44
- if (!importID) {
45
- // look for an import from the source module
46
- const has_import = script.body.find(
47
- (statement) =>
48
- statement.type === 'ImportDeclaration' && statement.source.value === sourceModule
49
- )
50
- if (!has_import) {
51
- script.body.unshift({
52
- type: 'ImportDeclaration',
53
- source: AST.stringLiteral(sourceModule),
54
- importKind,
55
- })
56
- }
57
-
58
- return { ids: [], added: has_import ? 0 : 1 }
59
- }
60
-
61
- const idList = (Array.isArray(importID) ? importID : [importID]).map((id) => AST.identifier(id))
62
-
63
- // figure out the list of things to import
64
- const toImport = idList.filter(
65
- (identifier) =>
66
- !script.body.find(
67
- (statement) =>
68
- statement.type === 'ImportDeclaration' &&
69
- (statement as unknown as ImportDeclaration).specifiers?.find(
70
- (importSpecifier) =>
71
- (importSpecifier.type === 'ImportSpecifier' &&
72
- importSpecifier.imported.type === 'Identifier' &&
73
- importSpecifier.imported.name === identifier.name &&
74
- importSpecifier.local?.name === identifier.name) ||
75
- (importSpecifier.type === 'ImportDefaultSpecifier' &&
76
- importSpecifier.local?.type === 'Identifier' &&
77
- importSpecifier.local.name === identifier.name &&
78
- importSpecifier.local.name === identifier.name)
79
- )
80
- )
81
- )
82
-
83
- // add the import if it doesn't exist, add it
84
- if (toImport.length > 0) {
85
- script.body.unshift({
86
- type: 'ImportDeclaration',
87
- source: AST.stringLiteral(sourceModule),
88
- specifiers: toImport.map((identifier, i) =>
89
- !Array.isArray(importID)
90
- ? AST.importDefaultSpecifier(identifier)
91
- : AST.importSpecifier(identifier, as?.[i] ? AST.identifier(as[i]) : identifier)
92
- ),
93
- importKind,
94
- })
95
- }
96
-
97
- // the resulting identifiers might have been aliased the as aliases if they exist
98
- for (const [i, target] of (as ?? []).entries()) {
99
- if (target) {
100
- idList[i] = AST.identifier(target)
101
- }
102
- }
103
-
104
- return {
105
- ids: Array.isArray(importID) ? idList : idList[0],
106
- added: toImport.length,
107
- }
108
- }
109
-
110
- export function artifact_import({
111
- config,
112
- script,
113
- artifact,
114
- local,
115
- }: {
116
- page: TransformPage
117
- config: Config
118
- script: Script
119
- artifact: { name: string }
120
- local?: string
121
- }) {
122
- const { ids, added } = ensure_imports({
123
- config,
124
- script,
125
- sourceModule: config.artifactImportPath(artifact.name),
126
- import: local || `_${artifact.name}Artifact`,
127
- })
128
- return { id: ids, added }
129
- }
package/src/vite/index.ts DELETED
@@ -1,55 +0,0 @@
1
- import minimatch from 'minimatch'
2
- import type { Plugin } from 'vite'
3
- import watch_and_run from 'vite-plugin-watch-and-run'
4
-
5
- import generate from '../codegen'
6
- import { getConfig, PluginConfig, formatErrors, path } from '../lib'
7
- import houdini_vite from './houdini'
8
- import watch_remote_schema from './schema'
9
-
10
- export * from './ast'
11
- export * from './imports'
12
- export * from './schema'
13
- export * from './houdini'
14
-
15
- export default function (opts?: PluginConfig): Plugin[] {
16
- // we need some way for the graphql tag to detect that we are running on the server
17
- // so we don't get an error when importing.
18
- process.env.HOUDINI_PLUGIN = 'true'
19
-
20
- return [
21
- houdini_vite(opts),
22
- watch_remote_schema(opts),
23
- watch_and_run([
24
- {
25
- name: 'Houdini',
26
- quiet: true,
27
- async watchFile(filepath: string) {
28
- // load the config file
29
- const config = await getConfig(opts)
30
-
31
- // we need to watch some specific files
32
- const schemaPath = path.join(path.dirname(config.filepath), config.schemaPath!)
33
- if (minimatch(filepath, schemaPath)) {
34
- return true
35
- }
36
-
37
- return config.includeFile(filepath, { root: process.cwd() })
38
- },
39
- async run() {
40
- // load the config file
41
- const config = await getConfig(opts)
42
-
43
- // make sure we behave as if we're generating from inside the plugin (changes logging behavior)
44
- config.pluginMode = true
45
-
46
- // generate the runtime
47
- await generate(config)
48
- },
49
- delay: 100,
50
- watchKind: ['add', 'change', 'unlink'],
51
- formatErrors,
52
- },
53
- ]),
54
- ]
55
- }
@@ -1,80 +0,0 @@
1
- import { sleep } from '@kitql/helper'
2
- import type { Plugin } from 'vite'
3
-
4
- import { formatErrors, getConfig, pullSchema, PluginConfig, path, fs } from '../lib'
5
-
6
- export default function HoudiniWatchSchemaPlugin(opts: PluginConfig = {}): Plugin {
7
- let go = true
8
-
9
- return {
10
- name: 'houdini-watch-schema',
11
- apply: 'serve',
12
- async buildStart() {
13
- const config = await getConfig(opts)
14
- let nbPullError = 0
15
-
16
- // validate the config
17
-
18
- // if there's no api url set, there's nothing to poll
19
- if (!config.apiUrl) {
20
- return
21
- }
22
-
23
- // if the schema path is a glob, there's no reason to poll (the schema is already local)
24
- if (config.schemaPath && fs.glob.hasMagic(config.schemaPath)) {
25
- return
26
- }
27
-
28
- const interval = config.schemaPollInterval
29
-
30
- // an interval of null means no initial poll
31
- if (interval === null) {
32
- return
33
- }
34
-
35
- // the function to call on the appropriate interval
36
- async function pull(more: boolean) {
37
- try {
38
- // Write the schema
39
- const schemaState = await pullSchema(
40
- config.apiUrl!,
41
- config.schemaPath ?? path.resolve(process.cwd(), 'schema.json'),
42
- config.pullHeaders
43
- )
44
-
45
- nbPullError = schemaState ? 0 : nbPullError + 1
46
- } catch (e) {
47
- formatErrors(e)
48
- }
49
-
50
- // if we are supposed to poll more, wait the appropriate amount of time and then do it again
51
- if (more) {
52
- // Wait more and more and more...
53
- const timeToWait = interval! + interval! * nbPullError
54
- await sleep(timeToWait)
55
-
56
- if (go) {
57
- pull(more)
58
- }
59
- }
60
- }
61
-
62
- // its safe to pull the schema
63
- await pull(false)
64
-
65
- // if we aren't supposed to poll at all
66
- if (interval <= 0) {
67
- return
68
- }
69
-
70
- // wait once before starting the loop
71
- await sleep(interval)
72
-
73
- // start listening
74
- await pull(true)
75
- },
76
- buildEnd() {
77
- go = false
78
- },
79
- }
80
- }