@znight/graphql 0.0.0 → 0.2.1

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 (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1346 -0
  3. package/dist/compiler.d.mts +114 -0
  4. package/dist/compiler.mjs +4599 -0
  5. package/dist/compiler.mjs.map +1 -0
  6. package/dist/index.d.mts +583 -0
  7. package/dist/index.mjs +134 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/names-BlzDM5cF.mjs +111 -0
  10. package/dist/names-BlzDM5cF.mjs.map +1 -0
  11. package/dist/plugin-CR_wVfRU.mjs +3445 -0
  12. package/dist/plugin-CR_wVfRU.mjs.map +1 -0
  13. package/dist/testing.d.mts +101 -0
  14. package/dist/testing.mjs +306 -0
  15. package/dist/testing.mjs.map +1 -0
  16. package/dist/types-DQ713UgI.d.mts +266 -0
  17. package/package.json +97 -1
  18. package/src/compiler/analyze.ts +727 -0
  19. package/src/compiler/builder.ts +1561 -0
  20. package/src/compiler/checks.ts +105 -0
  21. package/src/compiler/conformance.ts +1068 -0
  22. package/src/compiler/constants.ts +80 -0
  23. package/src/compiler/data.ts +83 -0
  24. package/src/compiler/defaults.ts +92 -0
  25. package/src/compiler/discriminators.ts +53 -0
  26. package/src/compiler/docs.ts +55 -0
  27. package/src/compiler/generate.ts +419 -0
  28. package/src/compiler/graphql-js.ts +42 -0
  29. package/src/compiler/ids.ts +128 -0
  30. package/src/compiler/index.ts +98 -0
  31. package/src/compiler/locate.ts +82 -0
  32. package/src/compiler/model.ts +137 -0
  33. package/src/compiler/options.ts +85 -0
  34. package/src/compiler/scalars.ts +138 -0
  35. package/src/compiler/schema-first.ts +595 -0
  36. package/src/compiler/sdl-source.ts +529 -0
  37. package/src/compiler/sdl-view.ts +61 -0
  38. package/src/compiler/suggest.ts +39 -0
  39. package/src/context.ts +181 -0
  40. package/src/decisions.ts +169 -0
  41. package/src/decorators.ts +202 -0
  42. package/src/errors.ts +89 -0
  43. package/src/execution.ts +1064 -0
  44. package/src/format.ts +285 -0
  45. package/src/index.ts +89 -0
  46. package/src/limits.ts +177 -0
  47. package/src/loaders.ts +149 -0
  48. package/src/memory-pubsub.ts +133 -0
  49. package/src/metadata.ts +222 -0
  50. package/src/names.ts +47 -0
  51. package/src/options.ts +331 -0
  52. package/src/pipeline.ts +338 -0
  53. package/src/plugin.ts +579 -0
  54. package/src/pubsub.ts +36 -0
  55. package/src/results.ts +206 -0
  56. package/src/scalars.ts +138 -0
  57. package/src/schema-hash.ts +18 -0
  58. package/src/schema.ts +635 -0
  59. package/src/sdl.ts +530 -0
  60. package/src/testing.ts +454 -0
  61. package/src/tokens.ts +22 -0
  62. package/src/transport/abort.ts +80 -0
  63. package/src/transport/accept.ts +155 -0
  64. package/src/transport/graphiql.ts +106 -0
  65. package/src/transport/http.ts +373 -0
  66. package/src/transport/sse.ts +45 -0
  67. package/src/type-ref.ts +89 -0
  68. package/src/types.ts +225 -0
  69. package/src/validate-args.ts +48 -0
@@ -0,0 +1,114 @@
1
+ import { Scope } from "@znight/core";
2
+ import { MetaEntry } from "@znight/http/compiler";
3
+ import { BindingHandle, ClassInfo, ClassRef, CompilerExtension, Location, ValueRef } from "@znight/compiler";
4
+ /** Kind of field a resolver method provides. */
5
+ type FieldOperation = "query" | "mutation" | "subscription" | "field";
6
+ /** A `@Resolver` class. */
7
+ interface ResolverData {
8
+ readonly kind: "resolver";
9
+ /** The resolver class; its identity is the provider token. */
10
+ readonly host: ClassInfo;
11
+ readonly scope: Scope;
12
+ /** Location of `@Resolver`. */
13
+ readonly location: Location;
14
+ /**
15
+ * `@Resolver('Event')`: the SDL object type its `@ResolveField` methods belong to (schema-first,
16
+ * RFC 0007), with the location of the argument.
17
+ */
18
+ readonly typeName?: {
19
+ readonly name: string;
20
+ readonly location: Location;
21
+ };
22
+ /**
23
+ * Schema-first: a class the analysis rejected (an error was reported); it only tells which fields
24
+ * its methods name (never bound, never a provider).
25
+ */
26
+ readonly invalid?: true;
27
+ /** Class `@UseGuard` guards. */
28
+ readonly guards: readonly ClassRef[];
29
+ /** One entry per field decorator of the class's methods, in source order. */
30
+ readonly fields: readonly FieldData[];
31
+ }
32
+ /** One `@Query`, `@Mutation`, `@Subscription` or `@ResolveField` decorator. */
33
+ interface FieldData {
34
+ /** Method name. */
35
+ readonly method: string;
36
+ readonly operation: FieldOperation;
37
+ /** GraphQL field name (decorator argument, or the method name). */
38
+ readonly name: string;
39
+ /** Location of the field decorator. */
40
+ readonly location: Location;
41
+ /** Location of the method name. */
42
+ readonly methodLocation: Location;
43
+ /** Method `@UseGuard` guards (class guards are on {@link ResolverData.guards}). */
44
+ readonly guards: readonly ClassRef[];
45
+ /** Effective route metadata: the class entries a method decision does not replace, then the method's. */
46
+ readonly meta: readonly MetaEntry[];
47
+ /** One entry per method parameter, by index (`undefined`: the parameter could not be analysed). */
48
+ readonly params: readonly (ParamData | undefined)[];
49
+ /** `false` when a parameter or the method could not be analysed (an error was reported). */
50
+ readonly complete: boolean;
51
+ }
52
+ /** What a method parameter receives (§7.3). */
53
+ type ParamData = {
54
+ readonly kind: "args";
55
+ /** `@Args('name')`: one argument; `undefined`: the properties of the type are the arguments. */
56
+ readonly name: string | undefined;
57
+ /** `@Args(..., Schema)`: the Standard Schema validating the value. */
58
+ readonly schema: ValueRef | undefined;
59
+ readonly location: Location;
60
+ } | {
61
+ readonly kind: "parent";
62
+ readonly location: Location;
63
+ } | {
64
+ readonly kind: "ctx";
65
+ } | {
66
+ readonly kind: "info";
67
+ } | {
68
+ readonly kind: "loader";
69
+ /** Binding of the loader provider (lazy edge from the resolver). */
70
+ readonly binding: BindingHandle;
71
+ /** Identity of `L` in `Loader<L>`. */
72
+ readonly identity: string;
73
+ readonly location: Location;
74
+ };
75
+ /** Everything the extension stores. */
76
+ type GraphQLData = ResolverData;
77
+ /**
78
+ * Options of the compiler extension (RFC 0005 §6.7, RFC 0007 §4.1), given with
79
+ * `graphql.configure({ ... })` in `znight.config.ts`. Import-free.
80
+ */
81
+ /** Options of `graphql.configure()`. */
82
+ interface GraphQLCompilerOptions {
83
+ /**
84
+ * Path of the SDL artifact, relative to the project root (`'schema.graphql'`), written next to the
85
+ * generated module and checked by `znight generate --check`. Default `false`: no file.
86
+ */
87
+ readonly sdl?: string | false;
88
+ /** GraphQL type of `number`. Default `'Float'`; `'Int'` suits counts and identifiers. Code-first only. */
89
+ readonly number?: "Float" | "Int";
90
+ /**
91
+ * Schema-first mode (RFC 0007): globs of the `.graphql` files that define the schema, relative to
92
+ * the project root (`'src/**\/*.graphql'`, `!` negations allowed). Resolvers are bound to their
93
+ * fields by name and checked against the SDL. Default `false`: code-first.
94
+ */
95
+ readonly schema?: string | readonly string[] | false;
96
+ }
97
+ /** {@link GraphQLCompilerOptions} with their defaults. */
98
+ interface ResolvedGraphQLCompilerOptions {
99
+ readonly sdl: string | false;
100
+ readonly number: "Float" | "Int";
101
+ /** The schema-first globs; `false`: code-first. */
102
+ readonly schema: readonly string[] | false;
103
+ }
104
+ /** The `@znight/graphql` compiler extension, with its options and `configure()`. */
105
+ export interface GraphQLCompilerExtension extends CompilerExtension<GraphQLData> {
106
+ /** The options of this copy (defaults filled in). */
107
+ readonly options: ResolvedGraphQLCompilerOptions;
108
+ /** A copy of the extension with `options` merged onto the options of this one. */
109
+ configure(options: GraphQLCompilerOptions): GraphQLCompilerExtension;
110
+ }
111
+ /** The `@znight/graphql` compiler extension with its default options. */
112
+ export declare const graphqlCompilerExtension: GraphQLCompilerExtension;
113
+ export { type FieldData, type FieldOperation, type GraphQLCompilerOptions, type GraphQLData, type ParamData, type ResolvedGraphQLCompilerOptions, type ResolverData, graphqlCompilerExtension as default };
114
+ //# sourceMappingURL=compiler.d.mts.map