@orion-js/graphql 4.3.1 → 4.4.0

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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/dist/buildSchema/getArgs/getField.d.ts +7 -0
  3. package/dist/buildSchema/getArgs/index.d.ts +3 -0
  4. package/dist/buildSchema/getMutation.d.ts +3 -0
  5. package/dist/buildSchema/getQuery.d.ts +3 -0
  6. package/dist/buildSchema/getResolvers/index.d.ts +3 -0
  7. package/dist/buildSchema/getResolvers/resolversStore.d.ts +3 -0
  8. package/dist/buildSchema/getSubscription.d.ts +3 -0
  9. package/dist/buildSchema/getSubscriptions/index.d.ts +2 -0
  10. package/dist/buildSchema/getType/BigIntScalar.d.ts +3 -0
  11. package/dist/buildSchema/getType/DateScalar.d.ts +3 -0
  12. package/dist/buildSchema/getType/JSONScalar.d.ts +3 -0
  13. package/dist/buildSchema/getType/getScalar.d.ts +1 -0
  14. package/dist/buildSchema/getType/getTypeAsResolver.d.ts +10 -0
  15. package/dist/buildSchema/getType/index.d.ts +6 -0
  16. package/dist/buildSchema/index.d.ts +3 -0
  17. package/dist/errorHandler.d.ts +1 -0
  18. package/dist/getApolloOptions/formatError.d.ts +1 -0
  19. package/dist/getApolloOptions/index.d.ts +3 -0
  20. package/dist/index.cjs +36 -36
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +13 -172
  23. package/dist/index.js +35 -32
  24. package/dist/index.js.map +1 -1
  25. package/dist/pubsub.d.ts +3 -0
  26. package/dist/resolversSchemas/ResolverParamsInfo.d.ts +15 -0
  27. package/dist/resolversSchemas/getBasicResultQuery.d.ts +2 -0
  28. package/dist/resolversSchemas/getDynamicFields.d.ts +2 -0
  29. package/dist/resolversSchemas/getField.d.ts +2 -0
  30. package/dist/resolversSchemas/getModelLoadedResolvers.d.ts +3 -0
  31. package/dist/resolversSchemas/getStaticFields.d.ts +2 -0
  32. package/dist/resolversSchemas/index.d.ts +11 -0
  33. package/dist/resolversSchemas/params.d.ts +10 -0
  34. package/dist/resolversSchemas/serializeSchema.d.ts +2 -0
  35. package/dist/service/global.d.ts +15 -0
  36. package/dist/service/index.d.ts +4 -0
  37. package/dist/service/middlewares.d.ts +6 -0
  38. package/dist/service/model.d.ts +13 -0
  39. package/dist/service/subscription.d.ts +6 -0
  40. package/dist/startGraphQL.d.ts +2 -0
  41. package/dist/startGraphiQL.d.ts +3 -0
  42. package/dist/startWebsocket.d.ts +11 -0
  43. package/dist/subscription/getChannelName.d.ts +1 -0
  44. package/dist/subscription/index.d.ts +3 -0
  45. package/dist/types/index.d.ts +3 -0
  46. package/dist/types/startGraphQL.d.ts +51 -0
  47. package/dist/types/subscription.d.ts +23 -0
  48. package/dist/websockerViewer.d.ts +2 -0
  49. package/package.json +19 -20
  50. package/dist/index.d.cts +0 -172
package/dist/index.d.ts CHANGED
@@ -1,172 +1,13 @@
1
- import * as _orion_js_resolvers from '@orion-js/resolvers';
2
- import { ResolverOptions, GlobalResolverOptions, GlobalResolver, ModelResolver as ModelResolver$1, ResolverMiddleware } from '@orion-js/resolvers';
3
- export { createResolver } from '@orion-js/resolvers';
4
- import * as _orion_js_schema from '@orion-js/schema';
5
- import { SchemaFieldType, InferSchemaType, Schema, SchemaWithMetadata, SchemaNode, SchemaInAnyOrionForm } from '@orion-js/schema';
6
- import { ModelResolversMap, GlobalResolversMap } from '@orion-js/models';
7
- import { express } from '@orion-js/http';
8
- import { PubSubEngine } from 'graphql-subscriptions';
9
- import { ApolloServerOptions } from '@apollo/server';
10
- import * as graphql from 'graphql';
11
- export { graphql as GraphQL };
12
-
13
- declare class OrionSubscription<TParamsSchema extends SchemaFieldType = SchemaFieldType, TReturnsSchema extends SchemaFieldType = SchemaFieldType> {
14
- name: string;
15
- params: TParamsSchema;
16
- subscribe: (callParams: InferSchemaType<TParamsSchema>, viewer: InferSchemaType<TReturnsSchema>) => {};
17
- returns: TReturnsSchema;
18
- publish: (params: InferSchemaType<TParamsSchema>, data: InferSchemaType<TReturnsSchema>) => Promise<void>;
19
- }
20
- type CreateOrionSubscriptionFunction = <TParamsSchema extends SchemaFieldType = SchemaFieldType, TReturnsSchema extends SchemaFieldType = SchemaFieldType, TViewer = any>(options: OrionSubscriptionOptions<TParamsSchema, TReturnsSchema, TViewer>) => OrionSubscription<TParamsSchema, TReturnsSchema>;
21
- interface OrionSubscriptionsMap {
22
- [key: string]: OrionSubscription;
23
- }
24
- type OrionSubscriptionOptions<TParamsSchema extends SchemaFieldType = SchemaFieldType, TReturnsSchema extends SchemaFieldType = SchemaFieldType, TViewer = any> = Omit<ResolverOptions<TParamsSchema, TReturnsSchema, TViewer>, 'resolve'> & {
25
- /**
26
- * This function is used to check if the user can subscribe to the subscription.
27
- * If not provided, the subscription will be public.
28
- * @param params - The parameters of the subscription.
29
- * @param viewer - The viewer of the subscription.
30
- * @returns true if the user can subscribe to the subscription, false otherwise.
31
- */
32
- canSubscribe?: (params: InferSchemaType<TParamsSchema>, viewer: TViewer) => Promise<boolean>;
33
- };
34
-
35
- type ExecuteGraphQLCache = (req: express.Request, res: express.Response, viewer: object, executeQuery: () => Promise<string>) => Promise<string>;
36
- interface ModelsResolversMap {
37
- [key: string]: ModelResolversMap;
38
- }
39
- type SchemaOmits = 'schema' | 'schemaHash' | 'context' | 'useGraphiql';
40
- interface StartGraphQLOptions extends Omit<ApolloServerOptions<any>, SchemaOmits> {
41
- /**
42
- * A map with all the global resolvers
43
- */
44
- resolvers: GlobalResolversMap;
45
- /**
46
- * A map with all the model resolvers. You must only add the models that you want to extend with resolvers.
47
- */
48
- modelResolvers?: ModelsResolversMap;
49
- /**
50
- * A Map with all global subscriptions
51
- */
52
- subscriptions?: OrionSubscriptionsMap;
53
- /**
54
- * A function that executes the http level cache of graphql queries
55
- */
56
- /**
57
- * Should use GraphiQL. Default to true
58
- */
59
- useGraphiql?: boolean;
60
- /**
61
- * Pass another express app
62
- */
63
- app?: express.Application;
64
- /**
65
- * The pubsub provider to use. Default to the single server pubsub.
66
- * If you are using multiple servers you must pass a pubsub provider like RedisPubSub
67
- */
68
- pubsub?: PubSubEngine;
69
- /**
70
- * Path to the graphql endpoint. Default to /graphql
71
- */
72
- path?: string;
73
- /**
74
- * Body parser options for the graphql endpoint.
75
- */
76
- bodyParserOptions?: {
77
- limit?: number | string | undefined;
78
- };
79
- }
80
-
81
- declare const createSubscription$1: CreateOrionSubscriptionFunction;
82
-
83
- declare function export_default$1(options: StartGraphQLOptions): Promise<void>;
84
-
85
- declare function export_default(apolloOptions: ApolloServerOptions<any>, options: StartGraphQLOptions): void;
86
-
87
- declare const _default$1: {
88
- params: _orion_js_resolvers.GlobalResolver<{
89
- name: {
90
- type: "ID";
91
- };
92
- mutation: {
93
- type: BooleanConstructor;
94
- };
95
- }, {
96
- name: {
97
- type: "string";
98
- };
99
- params: {
100
- type: "blackbox";
101
- };
102
- result: {
103
- type: "string";
104
- };
105
- basicResultQuery: {
106
- type: "string";
107
- };
108
- }, any, any>;
109
- };
110
-
111
- declare const _default: {
112
- name: {
113
- type: "string";
114
- };
115
- params: {
116
- type: "blackbox";
117
- };
118
- result: {
119
- type: "string";
120
- };
121
- basicResultQuery: {
122
- type: "string";
123
- };
124
- };
125
-
126
- declare function serializeSchema(params: Schema): Promise<SchemaWithMetadata>;
127
-
128
- declare function getBasicQuery(field: SchemaNode): Promise<string>;
129
-
130
- declare const createQuery: <TParams extends SchemaFieldType = any, TReturns extends SchemaFieldType = any, TViewer = any, TInfo = any>(options: GlobalResolverOptions<TParams, TReturns, TViewer, TInfo>) => GlobalResolver<TParams, TReturns, TViewer, TInfo>;
131
- declare const createMutation: <TParams extends SchemaFieldType = any, TReturns extends SchemaFieldType = any, TViewer = any, TInfo = any>(options: Omit<GlobalResolverOptions<TParams, TReturns, TViewer, TInfo>, "mutation">) => GlobalResolver<TParams, TReturns, TViewer, TInfo>;
132
- declare const internalResolversMetadata: WeakMap<any, Record<string, any>>;
133
- declare function Resolvers(): (target: any, context: ClassDecoratorContext<any>) => void;
134
- declare function Query(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
135
- declare function Query(options?: Omit<ResolverOptions<any>, 'resolve' | 'mutation'>): (method: any, context: ClassMethodDecoratorContext) => any;
136
- declare function Mutation(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
137
- declare function Mutation(options?: Omit<ResolverOptions<any>, 'resolve' | 'mutation'>): (method: any, context: ClassMethodDecoratorContext) => any;
138
- declare function registerPendingResolver(propertyKey: string, setup: (instance: any) => any): void;
139
- declare function getServiceResolvers(target: any): {
140
- [key: string]: GlobalResolver<any, any, any, any>;
141
- };
142
-
143
- declare const createModelResolver: <TItem = any, TParams extends _orion_js_schema.SchemaFieldType = any, TReturns extends _orion_js_schema.SchemaFieldType = any, TViewer = any, TInfo = any>(options: _orion_js_resolvers.ModelResolverOptions<TItem, TParams, TReturns, TViewer, TInfo>) => ModelResolver$1<TItem, TParams, TReturns, TViewer, TInfo>;
144
- interface ModelResolversOptions {
145
- modelName?: string;
146
- }
147
- declare function ModelResolvers(typedSchema: any, options?: ModelResolversOptions): (target: any, context: ClassDecoratorContext<any>) => void;
148
- declare function ModelResolver(): (method: any, context: ClassFieldDecoratorContext | ClassMethodDecoratorContext) => any;
149
- declare function ModelResolver(options?: Omit<ResolverOptions<any>, 'resolve' | 'middlewares'>): (method: any, context: ClassMethodDecoratorContext) => any;
150
- declare function getServiceModelResolvers(target: any): {
151
- [key: string]: {
152
- [key: string]: ModelResolver$1;
153
- };
154
- };
155
-
156
- declare function Subscriptions(): (target: any, context: ClassDecoratorContext<any>) => void;
157
- declare function Subscription(): (method: any, context: ClassFieldDecoratorContext) => any;
158
- declare function getServiceSubscriptions(target: any): {
159
- [key: string]: OrionSubscription;
160
- };
161
-
162
- declare function getTargetMetadata(target: any, propertyKey: string, metadataKey: string): any;
163
- declare function UseMiddleware<TMiddleware extends ResolverMiddleware, This>(params: TMiddleware): (method: any, context: ClassMethodDecoratorContext<This, typeof method>) => any;
164
- declare function ResolverParams<TParams extends SchemaInAnyOrionForm, This>(params: TParams): (method: any, context: ClassMethodDecoratorContext<This, typeof method>) => any;
165
- declare function ResolverReturns<This>(returns: any): (method: any, context: ClassMethodDecoratorContext<This, typeof method>) => any;
166
-
167
- declare const getWebsockerViewer: (connectionParams: any) => Promise<any>;
168
- declare const setGetWebsockerViewer: (getViewerFunc: (connectionParams: any) => any) => void;
169
-
170
- declare const createSubscription: CreateOrionSubscriptionFunction;
171
-
172
- export { type CreateOrionSubscriptionFunction, type ExecuteGraphQLCache, ModelResolver, ModelResolvers, type ModelResolversOptions, type ModelsResolversMap, Mutation, OrionSubscription, type OrionSubscriptionOptions, type OrionSubscriptionsMap, Query, ResolverParams, _default as ResolverParamsInfo, ResolverReturns, Resolvers, type StartGraphQLOptions, Subscription, Subscriptions, UseMiddleware, createModelResolver, createMutation, createQuery, createSubscription, getBasicQuery as getBasicResultQuery, getServiceModelResolvers, getServiceResolvers, getServiceSubscriptions, getTargetMetadata, getWebsockerViewer, internalResolversMetadata, registerPendingResolver, _default$1 as resolversSchemas, serializeSchema, setGetWebsockerViewer, export_default$1 as startGraphQL, export_default as startGraphiQL, createSubscription$1 as subscription };
1
+ import subscription from './subscription';
2
+ import startGraphQL from './startGraphQL';
3
+ import startGraphiQL from './startGraphiQL';
4
+ import resolversSchemas from './resolversSchemas';
5
+ import ResolverParamsInfo from './resolversSchemas/ResolverParamsInfo';
6
+ import serializeSchema from './resolversSchemas/serializeSchema';
7
+ import getBasicResultQuery from './resolversSchemas/getBasicResultQuery';
8
+ import * as GraphQL from 'graphql';
9
+ declare const createSubscription: import("./types").CreateOrionSubscriptionFunction;
10
+ export { GraphQL, startGraphQL, startGraphiQL, resolversSchemas, ResolverParamsInfo, serializeSchema, subscription, createSubscription, getBasicResultQuery, };
11
+ export * from './types';
12
+ export * from './service';
13
+ export * from './websockerViewer';
package/dist/index.js CHANGED
@@ -769,14 +769,16 @@ function getDynamicFields(schema) {
769
769
  // src/resolversSchemas/getModelLoadedResolvers.ts
770
770
  function getModelLoadedResolvers(schema, options) {
771
771
  if (!options.modelResolvers) return [];
772
+ if (!schema.__modelName) return [];
772
773
  const resolvers = options.modelResolvers[schema.__modelName];
773
774
  if (!resolvers) return [];
774
775
  const keys = Object.keys(resolvers);
775
776
  return keys.map((key) => {
776
777
  const resolver = resolvers[key];
777
- resolver.resolverName = key;
778
+ const namedResolver = resolver;
779
+ namedResolver.resolverName = key;
778
780
  return {
779
- ...resolver,
781
+ ...namedResolver,
780
782
  key
781
783
  };
782
784
  }).filter((resolver) => !resolver.private);
@@ -1095,8 +1097,34 @@ async function startGraphQL_default(options) {
1095
1097
  }
1096
1098
 
1097
1099
  // src/resolversSchemas/params.ts
1098
- import { createResolver } from "@orion-js/resolvers";
1099
1100
  import { UserError } from "@orion-js/helpers";
1101
+ import { createResolver } from "@orion-js/resolvers";
1102
+ import {
1103
+ getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm4,
1104
+ isSchemaLike as isSchemaLike5
1105
+ } from "@orion-js/schema";
1106
+
1107
+ // src/resolversSchemas/getBasicResultQuery.ts
1108
+ import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm2, isSchemaLike as isSchemaLike3 } from "@orion-js/schema";
1109
+ async function getBasicQuery(field) {
1110
+ if (!field.type) return "";
1111
+ if (Array.isArray(field.type)) {
1112
+ return getBasicQuery({
1113
+ ...field,
1114
+ type: field.type[0]
1115
+ });
1116
+ }
1117
+ if (!isSchemaLike3(field.type)) {
1118
+ return field.key;
1119
+ }
1120
+ const schema = getSchemaFromAnyOrionForm2(field.type);
1121
+ const fields = [];
1122
+ for (const field2 of getStaticFields(schema)) {
1123
+ fields.push(await getBasicQuery(field2));
1124
+ }
1125
+ const key = field.key ? `${field.key} ` : "";
1126
+ return `${key}{ ${fields.join(" ")} }`;
1127
+ }
1100
1128
 
1101
1129
  // src/resolversSchemas/ResolverParamsInfo.ts
1102
1130
  import { schemaWithName } from "@orion-js/schema";
@@ -1116,13 +1144,13 @@ var ResolverParamsInfo_default = schemaWithName("ResolverParams", {
1116
1144
  });
1117
1145
 
1118
1146
  // src/resolversSchemas/serializeSchema.ts
1119
- import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm2 } from "@orion-js/schema";
1147
+ import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm3 } from "@orion-js/schema";
1120
1148
 
1121
1149
  // src/resolversSchemas/getField.ts
1122
1150
  import {
1123
1151
  getFieldType as getFieldType3,
1124
1152
  getSchemaWithMetadataFromAnyOrionForm as getSchemaWithMetadataFromAnyOrionForm3,
1125
- isSchemaLike as isSchemaLike3
1153
+ isSchemaLike as isSchemaLike4
1126
1154
  } from "@orion-js/schema";
1127
1155
  async function getParams(field) {
1128
1156
  const { type: type2 } = field;
@@ -1134,7 +1162,7 @@ async function getParams(field) {
1134
1162
  __graphQLType: `[${serialized.__graphQLType}]`
1135
1163
  };
1136
1164
  }
1137
- const isSchema = isSchemaLike3(type2);
1165
+ const isSchema = isSchemaLike4(type2);
1138
1166
  if (isSchema) {
1139
1167
  const schemaOfType = getSchemaWithMetadataFromAnyOrionForm3(type2);
1140
1168
  const modelName = schemaOfType.__modelName;
@@ -1164,7 +1192,7 @@ async function getParams(field) {
1164
1192
  // src/resolversSchemas/serializeSchema.ts
1165
1193
  async function serializeSchema(params) {
1166
1194
  if (!params) return;
1167
- const schema = getSchemaFromAnyOrionForm2(params);
1195
+ const schema = getSchemaFromAnyOrionForm3(params);
1168
1196
  if (Object.keys(schema).length === 0) return;
1169
1197
  const fields = {};
1170
1198
  for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
@@ -1178,31 +1206,6 @@ async function serializeSchema(params) {
1178
1206
  return fields;
1179
1207
  }
1180
1208
 
1181
- // src/resolversSchemas/params.ts
1182
- import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm4, isSchemaLike as isSchemaLike5 } from "@orion-js/schema";
1183
-
1184
- // src/resolversSchemas/getBasicResultQuery.ts
1185
- import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm3, isSchemaLike as isSchemaLike4 } from "@orion-js/schema";
1186
- async function getBasicQuery(field) {
1187
- if (!field.type) return "";
1188
- if (Array.isArray(field.type)) {
1189
- return getBasicQuery({
1190
- ...field,
1191
- type: field.type[0]
1192
- });
1193
- }
1194
- if (!isSchemaLike4(field.type)) {
1195
- return field.key;
1196
- }
1197
- const schema = getSchemaFromAnyOrionForm3(field.type);
1198
- const fields = [];
1199
- for (const field2 of getStaticFields(schema)) {
1200
- fields.push(await getBasicQuery(field2));
1201
- }
1202
- const key = field.key ? `${field.key} ` : "";
1203
- return `${key}{ ${fields.join(" ")} }`;
1204
- }
1205
-
1206
1209
  // src/resolversSchemas/params.ts
1207
1210
  function getResultTypeName(type2) {
1208
1211
  const returns = Array.isArray(type2) ? type2[0] : type2;