sofa-api 0.11.2-alpha.0 → 0.12.0-alpha.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.
File without changes
File without changes
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { SofaConfig } from './sofa';
2
+ export { OpenAPI } from './open-api';
3
+ export declare function useSofa(config: SofaConfig): import("@whatwg-node/server").ServerAdapter<unknown, import("itty-router").Router<import("itty-router").Request & Request, {}>>;
@@ -13,8 +13,6 @@ const uuid = require('uuid');
13
13
  const fetch = require('@whatwg-node/fetch');
14
14
  const colors = _interopDefault(require('ansi-colors'));
15
15
  const server = require('@whatwg-node/server');
16
- const jsYaml = require('js-yaml');
17
- const fs = require('fs');
18
16
  const titleCase = require('title-case');
19
17
 
20
18
  function getOperationInfo(doc) {
@@ -63,7 +61,7 @@ function resolveVariable({ value, type, schema, }) {
63
61
  return value;
64
62
  }
65
63
  if (type.kind === graphql.Kind.LIST_TYPE) {
66
- return (Array.isArray(value) ? value : [value]).map(val => resolveVariable({
64
+ return (Array.isArray(value) ? value : [value]).map((val) => resolveVariable({
67
65
  value: val,
68
66
  type: type.type,
69
67
  schema,
@@ -182,7 +180,7 @@ class SubscriptionManager {
182
180
  }
183
181
  return Object.assign(Object.assign({}, values), { [name]: value });
184
182
  }, {});
185
- const execution = yield graphql.subscribe({
183
+ const execution = yield this.sofa.subscribe({
186
184
  schema: this.sofa.schema,
187
185
  document,
188
186
  operationName,
@@ -242,7 +240,7 @@ class SubscriptionManager {
242
240
  body: JSON.stringify(result),
243
241
  headers: {
244
242
  'Content-Type': 'application/json',
245
- }
243
+ },
246
244
  });
247
245
  yield response.text();
248
246
  });
@@ -300,9 +298,10 @@ function createRouter(sofa) {
300
298
  }
301
299
  });
302
300
  }
303
- router.post('/webhook', (request, contextValue) => tslib.__awaiter(this, void 0, void 0, function* () {
301
+ router.post('/webhook', (request, serverContext) => tslib.__awaiter(this, void 0, void 0, function* () {
304
302
  const { subscription, variables, url } = yield request.json();
305
303
  try {
304
+ const contextValue = yield sofa.contextFactory(serverContext);
306
305
  const result = yield subscriptionManager.start({
307
306
  subscription,
308
307
  variables,
@@ -323,12 +322,13 @@ function createRouter(sofa) {
323
322
  });
324
323
  }
325
324
  }));
326
- router.post('/webhook/:id', (request, contextValue) => tslib.__awaiter(this, void 0, void 0, function* () {
325
+ router.post('/webhook/:id', (request, serverContext) => tslib.__awaiter(this, void 0, void 0, function* () {
327
326
  var _a;
328
327
  const id = (_a = request.params) === null || _a === void 0 ? void 0 : _a.id;
329
328
  const body = yield request.json();
330
329
  const variables = body.variables;
331
330
  try {
331
+ const contextValue = yield sofa.contextFactory(serverContext);
332
332
  const result = yield subscriptionManager.update({
333
333
  id,
334
334
  variables,
@@ -443,7 +443,7 @@ function createMutationRoute({ sofa, router, fieldName, }) {
443
443
  function useHandler(config) {
444
444
  const { sofa, operation, fieldName } = config;
445
445
  const info = config.info;
446
- return (request, contextValue) => tslib.__awaiter(this, void 0, void 0, function* () {
446
+ return (request, serverContext) => tslib.__awaiter(this, void 0, void 0, function* () {
447
447
  var _a;
448
448
  let body = {};
449
449
  if (request.body != null) {
@@ -469,9 +469,10 @@ function useHandler(config) {
469
469
  }
470
470
  return Object.assign(Object.assign({}, variables), { [name]: value });
471
471
  }, {});
472
+ const contextValue = yield sofa.contextFactory(serverContext);
472
473
  const result = yield sofa.execute({
473
474
  schema: sofa.schema,
474
- source: graphql.print(operation),
475
+ document: operation,
475
476
  contextValue,
476
477
  variableValues,
477
478
  operationName: info.operation.name && info.operation.name.value,
@@ -517,9 +518,25 @@ function createSofa(config) {
517
518
  const depthLimit = config.depthLimit || 1;
518
519
  logger.debug(`[Sofa] models: ${models.join(', ')}`);
519
520
  logger.debug(`[Sofa] ignore: ${ignore.join(', ')}`);
520
- return Object.assign({ execute: graphql.graphql, models,
521
+ return Object.assign({ execute: graphql.execute,
522
+ subscribe: graphql.subscribe,
523
+ models,
521
524
  ignore,
522
- depthLimit }, config);
525
+ depthLimit,
526
+ contextFactory(serverContext) {
527
+ if (config.context != null) {
528
+ if (isContextFn(config.context)) {
529
+ return config.context(serverContext);
530
+ }
531
+ else {
532
+ return config.context;
533
+ }
534
+ }
535
+ return serverContext;
536
+ } }, config);
537
+ }
538
+ function isContextFn(context) {
539
+ return typeof context === 'function';
523
540
  }
524
541
  // Objects and Unions are the only things that are used to define return types
525
542
  // and both might contain an ID
@@ -704,7 +721,7 @@ function resolveRequestBody(variables) {
704
721
  }
705
722
  const properties = {};
706
723
  const required = [];
707
- variables.forEach(variable => {
724
+ variables.forEach((variable) => {
708
725
  if (variable.type.kind === graphql.Kind.NON_NULL_TYPE) {
709
726
  required.push(variable.variable.name.value);
710
727
  }
@@ -760,7 +777,7 @@ function resolveDescription(schema, operation) {
760
777
  if (!isObjectTypeDefinitionNode(definitionNode)) {
761
778
  return '';
762
779
  }
763
- const fieldNode = definitionNode.fields.find(field => field.name.value === fieldName);
780
+ const fieldNode = definitionNode.fields.find((field) => field.name.value === fieldName);
764
781
  const descriptionDefinition = fieldNode && fieldNode.description;
765
782
  return descriptionDefinition && descriptionDefinition.value
766
783
  ? descriptionDefinition.value
@@ -813,44 +830,12 @@ function OpenAPI({ schema, info, servers, components, security, tags, }) {
813
830
  get() {
814
831
  return swagger;
815
832
  },
816
- save(filepath) {
817
- const isJSON = /\.json$/i;
818
- const isYAML = /.ya?ml$/i;
819
- if (isJSON.test(filepath)) {
820
- writeOutput(filepath, JSON.stringify(swagger, null, 2));
821
- }
822
- else if (isYAML.test(filepath)) {
823
- writeOutput(filepath, jsYaml.dump(swagger));
824
- }
825
- else {
826
- throw new Error('We only support JSON and YAML files');
827
- }
828
- },
829
833
  };
830
- }
831
- function writeOutput(filepath, contents) {
832
- fs.writeFileSync(filepath, contents, {
833
- encoding: 'utf-8',
834
- });
835
834
  }
836
835
 
837
- function isContextFn(context) {
838
- return typeof context === 'function';
839
- }
840
- function useSofa(_a) {
841
- var config = tslib.__rest(_a, ["context"]);
842
- const sofaRouter = createSofaRouter(config);
843
- return server.createServerAdapter({
844
- handleRequest: sofaRouter.handle,
845
- });
846
- }
847
- function createSofaRouter(config) {
848
- const sofa = createSofa(config);
849
- const router = createRouter(sofa);
850
- return router;
836
+ function useSofa(config) {
837
+ return server.createServerAdapter(createRouter(createSofa(config)));
851
838
  }
852
839
 
853
840
  exports.OpenAPI = OpenAPI;
854
- exports.createSofaRouter = createSofaRouter;
855
- exports.isContextFn = isContextFn;
856
841
  exports.useSofa = useSofa;
@@ -1,5 +1,5 @@
1
- import { __awaiter, __asyncValues, __rest } from 'tslib';
2
- import { getOperationAST, Kind, isScalarType, isEqualType, GraphQLBoolean, isInputObjectType, subscribe, isObjectType, isNonNullType, print, graphql, getNamedType, isListType, isEnumType, parse, printType, isIntrospectionType } from 'graphql';
1
+ import { __awaiter, __asyncValues } from 'tslib';
2
+ import { getOperationAST, Kind, isScalarType, isEqualType, GraphQLBoolean, isInputObjectType, isObjectType, isNonNullType, execute, subscribe, getNamedType, isListType, isEnumType, parse, printType, isIntrospectionType } from 'graphql';
3
3
  import { Router } from 'itty-router';
4
4
  import { buildOperationNodeForField } from '@graphql-tools/utils';
5
5
  import { paramCase } from 'param-case';
@@ -7,8 +7,6 @@ import { v4 } from 'uuid';
7
7
  import { fetch, Response } from '@whatwg-node/fetch';
8
8
  import colors from 'ansi-colors';
9
9
  import { createServerAdapter } from '@whatwg-node/server';
10
- import { dump } from 'js-yaml';
11
- import { writeFileSync } from 'fs';
12
10
  import { titleCase } from 'title-case';
13
11
 
14
12
  function getOperationInfo(doc) {
@@ -57,7 +55,7 @@ function resolveVariable({ value, type, schema, }) {
57
55
  return value;
58
56
  }
59
57
  if (type.kind === Kind.LIST_TYPE) {
60
- return (Array.isArray(value) ? value : [value]).map(val => resolveVariable({
58
+ return (Array.isArray(value) ? value : [value]).map((val) => resolveVariable({
61
59
  value: val,
62
60
  type: type.type,
63
61
  schema,
@@ -176,7 +174,7 @@ class SubscriptionManager {
176
174
  }
177
175
  return Object.assign(Object.assign({}, values), { [name]: value });
178
176
  }, {});
179
- const execution = yield subscribe({
177
+ const execution = yield this.sofa.subscribe({
180
178
  schema: this.sofa.schema,
181
179
  document,
182
180
  operationName,
@@ -236,7 +234,7 @@ class SubscriptionManager {
236
234
  body: JSON.stringify(result),
237
235
  headers: {
238
236
  'Content-Type': 'application/json',
239
- }
237
+ },
240
238
  });
241
239
  yield response.text();
242
240
  });
@@ -294,9 +292,10 @@ function createRouter(sofa) {
294
292
  }
295
293
  });
296
294
  }
297
- router.post('/webhook', (request, contextValue) => __awaiter(this, void 0, void 0, function* () {
295
+ router.post('/webhook', (request, serverContext) => __awaiter(this, void 0, void 0, function* () {
298
296
  const { subscription, variables, url } = yield request.json();
299
297
  try {
298
+ const contextValue = yield sofa.contextFactory(serverContext);
300
299
  const result = yield subscriptionManager.start({
301
300
  subscription,
302
301
  variables,
@@ -317,12 +316,13 @@ function createRouter(sofa) {
317
316
  });
318
317
  }
319
318
  }));
320
- router.post('/webhook/:id', (request, contextValue) => __awaiter(this, void 0, void 0, function* () {
319
+ router.post('/webhook/:id', (request, serverContext) => __awaiter(this, void 0, void 0, function* () {
321
320
  var _a;
322
321
  const id = (_a = request.params) === null || _a === void 0 ? void 0 : _a.id;
323
322
  const body = yield request.json();
324
323
  const variables = body.variables;
325
324
  try {
325
+ const contextValue = yield sofa.contextFactory(serverContext);
326
326
  const result = yield subscriptionManager.update({
327
327
  id,
328
328
  variables,
@@ -437,7 +437,7 @@ function createMutationRoute({ sofa, router, fieldName, }) {
437
437
  function useHandler(config) {
438
438
  const { sofa, operation, fieldName } = config;
439
439
  const info = config.info;
440
- return (request, contextValue) => __awaiter(this, void 0, void 0, function* () {
440
+ return (request, serverContext) => __awaiter(this, void 0, void 0, function* () {
441
441
  var _a;
442
442
  let body = {};
443
443
  if (request.body != null) {
@@ -463,9 +463,10 @@ function useHandler(config) {
463
463
  }
464
464
  return Object.assign(Object.assign({}, variables), { [name]: value });
465
465
  }, {});
466
+ const contextValue = yield sofa.contextFactory(serverContext);
466
467
  const result = yield sofa.execute({
467
468
  schema: sofa.schema,
468
- source: print(operation),
469
+ document: operation,
469
470
  contextValue,
470
471
  variableValues,
471
472
  operationName: info.operation.name && info.operation.name.value,
@@ -511,9 +512,25 @@ function createSofa(config) {
511
512
  const depthLimit = config.depthLimit || 1;
512
513
  logger.debug(`[Sofa] models: ${models.join(', ')}`);
513
514
  logger.debug(`[Sofa] ignore: ${ignore.join(', ')}`);
514
- return Object.assign({ execute: graphql, models,
515
+ return Object.assign({ execute,
516
+ subscribe,
517
+ models,
515
518
  ignore,
516
- depthLimit }, config);
519
+ depthLimit,
520
+ contextFactory(serverContext) {
521
+ if (config.context != null) {
522
+ if (isContextFn(config.context)) {
523
+ return config.context(serverContext);
524
+ }
525
+ else {
526
+ return config.context;
527
+ }
528
+ }
529
+ return serverContext;
530
+ } }, config);
531
+ }
532
+ function isContextFn(context) {
533
+ return typeof context === 'function';
517
534
  }
518
535
  // Objects and Unions are the only things that are used to define return types
519
536
  // and both might contain an ID
@@ -698,7 +715,7 @@ function resolveRequestBody(variables) {
698
715
  }
699
716
  const properties = {};
700
717
  const required = [];
701
- variables.forEach(variable => {
718
+ variables.forEach((variable) => {
702
719
  if (variable.type.kind === Kind.NON_NULL_TYPE) {
703
720
  required.push(variable.variable.name.value);
704
721
  }
@@ -754,7 +771,7 @@ function resolveDescription(schema, operation) {
754
771
  if (!isObjectTypeDefinitionNode(definitionNode)) {
755
772
  return '';
756
773
  }
757
- const fieldNode = definitionNode.fields.find(field => field.name.value === fieldName);
774
+ const fieldNode = definitionNode.fields.find((field) => field.name.value === fieldName);
758
775
  const descriptionDefinition = fieldNode && fieldNode.description;
759
776
  return descriptionDefinition && descriptionDefinition.value
760
777
  ? descriptionDefinition.value
@@ -807,41 +824,11 @@ function OpenAPI({ schema, info, servers, components, security, tags, }) {
807
824
  get() {
808
825
  return swagger;
809
826
  },
810
- save(filepath) {
811
- const isJSON = /\.json$/i;
812
- const isYAML = /.ya?ml$/i;
813
- if (isJSON.test(filepath)) {
814
- writeOutput(filepath, JSON.stringify(swagger, null, 2));
815
- }
816
- else if (isYAML.test(filepath)) {
817
- writeOutput(filepath, dump(swagger));
818
- }
819
- else {
820
- throw new Error('We only support JSON and YAML files');
821
- }
822
- },
823
827
  };
824
- }
825
- function writeOutput(filepath, contents) {
826
- writeFileSync(filepath, contents, {
827
- encoding: 'utf-8',
828
- });
829
828
  }
830
829
 
831
- function isContextFn(context) {
832
- return typeof context === 'function';
833
- }
834
- function useSofa(_a) {
835
- var config = __rest(_a, ["context"]);
836
- const sofaRouter = createSofaRouter(config);
837
- return createServerAdapter({
838
- handleRequest: sofaRouter.handle,
839
- });
840
- }
841
- function createSofaRouter(config) {
842
- const sofa = createSofa(config);
843
- const router = createRouter(sofa);
844
- return router;
830
+ function useSofa(config) {
831
+ return createServerAdapter(createRouter(createSofa(config)));
845
832
  }
846
833
 
847
- export { OpenAPI, createSofaRouter, isContextFn, useSofa };
834
+ export { OpenAPI, useSofa };
File without changes
@@ -12,5 +12,4 @@ export declare function OpenAPI({ schema, info, servers, components, security, t
12
12
  basePath?: string;
13
13
  }): void;
14
14
  get(): any;
15
- save(filepath: string): void;
16
15
  };
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,108 +1,53 @@
1
1
  {
2
2
  "name": "sofa-api",
3
+ "version": "0.12.0-alpha.0",
3
4
  "description": "Create REST APIs with GraphQL",
4
- "version": "0.11.2-alpha.0",
5
- "buildOptions": {
6
- "input": "./src/index.ts"
7
- },
8
5
  "sideEffects": false,
9
- "main": "dist/index.js",
10
- "module": "dist/index.mjs",
11
- "exports": {
12
- ".": {
13
- "require": "./dist/index.js",
14
- "import": "./dist/index.mjs"
15
- },
16
- "./*": {
17
- "require": "./dist/*.js",
18
- "import": "./dist/*.mjs"
19
- }
20
- },
21
- "typings": "dist/index.d.ts",
22
- "typescript": {
23
- "definition": "dist/index.d.ts"
24
- },
25
- "license": "MIT",
26
- "keywords": [
27
- "api",
28
- "rest",
29
- "graphql",
30
- "sofa"
31
- ],
32
- "repository": {
33
- "type": "git",
34
- "url": "Urigo/sofa"
35
- },
36
- "author": {
37
- "name": "Uri Goldshtein",
38
- "email": "uri.goldshtein@gmail.com",
39
- "url": "https://github.com/Urigo"
40
- },
41
6
  "peerDependencies": {
42
7
  "graphql": "^0.13.2 || ^14.0.0 || ^15.0.0 || ^16.0.0"
43
8
  },
44
9
  "dependencies": {
45
10
  "@graphql-tools/utils": "8.12.0",
46
- "ansi-colors": "4.1.3",
47
11
  "@whatwg-node/fetch": "^0.4.3",
48
12
  "@whatwg-node/server": "^0.4.1",
13
+ "ansi-colors": "4.1.3",
49
14
  "itty-router": "^2.6.1",
50
15
  "param-case": "3.0.4",
51
16
  "title-case": "3.0.3",
52
17
  "tslib": "2.4.0",
53
18
  "uuid": "8.3.2"
54
19
  },
55
- "scripts": {
56
- "start": "ts-node --project tsconfig.example.json example/index.ts",
57
- "clean": "rm -rf dist",
58
- "prebuild": "yarn clean",
59
- "build": "bob build --single",
60
- "test": "jest --no-watchman",
61
- "prepare-release": "yarn build && yarn test",
62
- "release": "yarn prepare-release && bob prepack && npm publish dist",
63
- "ci:release:canary": "node bump.js && bob prepack && npm publish dist --tag alpha --access public",
64
- "postinstall": "husky install"
65
- },
66
- "devDependencies": {
67
- "@graphql-tools/schema": "9.0.4",
68
- "@graphql-yoga/node": "2.13.13",
69
- "@types/jest": "28.1.8",
70
- "@types/node": "14.18.29",
71
- "@types/swagger-ui-dist": "3.30.1",
72
- "@types/uuid": "8.3.4",
73
- "@types/yamljs": "0.2.31",
74
- "bob-the-bundler": "1.7.3",
75
- "bundlesize": "0.18.1",
76
- "chalk": "^4",
77
- "express": "4.18.1",
78
- "express-graphql": "0.12.0",
79
- "graphql": "16.6.0",
80
- "graphql-subscriptions": "2.0.0",
81
- "husky": "8.0.1",
82
- "jest": "28.1.3",
83
- "lint-staged": "13.0.3",
84
- "prettier": "2.7.1",
85
- "supertest": "6.2.4",
86
- "swagger-ui-dist": "4.14.0",
87
- "ts-jest": "28.0.8",
88
- "ts-node": "10.9.1",
89
- "typescript": "4.7.4"
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "Urigo/sofa"
90
23
  },
91
- "husky": {
92
- "hooks": {
93
- "pre-commit": "lint-staged"
94
- }
24
+ "keywords": [
25
+ "api",
26
+ "rest",
27
+ "graphql",
28
+ "sofa"
29
+ ],
30
+ "author": {
31
+ "name": "Uri Goldshtein",
32
+ "email": "uri.goldshtein@gmail.com",
33
+ "url": "https://github.com/Urigo"
95
34
  },
96
- "lint-staged": {
97
- "*.{ts,js,md,json}": [
98
- "prettier --write"
99
- ]
35
+ "license": "MIT",
36
+ "main": "index.js",
37
+ "module": "index.mjs",
38
+ "typings": "index.d.ts",
39
+ "typescript": {
40
+ "definition": "index.d.ts"
100
41
  },
101
- "bundlesize": [
102
- {
103
- "path": "./dist/index.mjs",
104
- "maxSize": "36 kB",
105
- "compression": "none"
106
- }
107
- ]
42
+ "exports": {
43
+ ".": {
44
+ "require": "./index.js",
45
+ "import": "./index.mjs"
46
+ },
47
+ "./*": {
48
+ "require": "./*.js",
49
+ "import": "./*.mjs"
50
+ },
51
+ "./package.json": "./package.json"
52
+ }
108
53
  }
File without changes
@@ -1,4 +1,6 @@
1
1
  import { Request as IttyRequest, Router } from 'itty-router';
2
2
  import type { Sofa } from './sofa';
3
3
  export declare type ErrorHandler = (errors: ReadonlyArray<any>) => Response;
4
- export declare function createRouter(sofa: Sofa): Router<IttyRequest, {}>;
4
+ declare type SofaRequest = IttyRequest & Request;
5
+ export declare function createRouter(sofa: Sofa): Router<SofaRequest, {}>;
6
+ export {};
@@ -1,5 +1,5 @@
1
- import { GraphQLSchema } from 'graphql';
2
- import { Ignore, ExecuteFn, OnRoute, Method } from './types';
1
+ import { GraphQLSchema, subscribe, execute } from 'graphql';
2
+ import { Ignore, OnRoute, Method, ContextFn, ContextValue } from './types';
3
3
  import { ErrorHandler } from './router';
4
4
  interface RouteConfig {
5
5
  method?: Method;
@@ -14,7 +14,8 @@ export interface Route {
14
14
  export interface SofaConfig {
15
15
  basePath: string;
16
16
  schema: GraphQLSchema;
17
- execute?: ExecuteFn;
17
+ execute?: typeof execute;
18
+ subscribe?: typeof subscribe;
18
19
  /**
19
20
  * Treats an Object with an ID as not a model.
20
21
  * @example ["User", "Message.author"]
@@ -27,6 +28,7 @@ export interface SofaConfig {
27
28
  * Overwrites the default HTTP route.
28
29
  */
29
30
  routes?: Record<string, RouteConfig>;
31
+ context?: ContextFn | ContextValue;
30
32
  }
31
33
  export interface Sofa {
32
34
  basePath: string;
@@ -35,9 +37,12 @@ export interface Sofa {
35
37
  ignore: Ignore;
36
38
  depthLimit: number;
37
39
  routes?: Record<string, RouteConfig>;
38
- execute: ExecuteFn;
40
+ execute: typeof execute;
41
+ subscribe: typeof subscribe;
39
42
  onRoute?: OnRoute;
40
43
  errorHandler?: ErrorHandler;
44
+ contextFactory: ContextFn;
41
45
  }
42
46
  export declare function createSofa(config: SofaConfig): Sofa;
47
+ export declare function isContextFn(context: any): context is ContextFn;
43
48
  export {};
File without changes
@@ -1,7 +1,6 @@
1
- import { GraphQLArgs, ExecutionResult, DocumentNode } from 'graphql';
1
+ import { DocumentNode } from 'graphql';
2
2
  export declare type ContextValue = Record<string, any>;
3
3
  export declare type Ignore = string[];
4
- export declare type ExecuteFn = (args: GraphQLArgs) => Promise<ExecutionResult<any>>;
5
4
  export declare type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
6
5
  export interface RouteInfo {
7
6
  document: DocumentNode;
@@ -9,3 +8,7 @@ export interface RouteInfo {
9
8
  method: Method;
10
9
  }
11
10
  export declare type OnRoute = (info: RouteInfo) => void;
11
+ export declare type ContextFn = (init: {
12
+ req: any;
13
+ res: any;
14
+ }) => Promise<ContextValue> | ContextValue;
package/CHANGELOG.md DELETED
@@ -1,50 +0,0 @@
1
- # Change log
2
-
3
- ### vNEXT
4
-
5
- ### v0.7.0
6
-
7
- - feat(swagger): custom components and security for OpenAPI [PR #296](https://github.com/Urigo/SOFA/pull/296)
8
-
9
- ### v0.6.1
10
-
11
- - fix(swagger): broken type of ID scalar in generated swagger document [PR #280](https://github.com/Urigo/SOFA/pull/280)
12
- - fix: do not resolve nil variables [PR #193](https://github.com/Urigo/SOFA/pull/193)
13
- - fix: use Kind from graphql instead of strings [PR #192](https://github.com/Urigo/SOFA/pull/192)
14
- - fix: replace request package with Axios [PR #194](https://github.com/Urigo/SOFA/pull/194)
15
-
16
- ### v0.6.0
17
-
18
- - fix(swagger): fix descriptions [PR #178](https://github.com/Urigo/SOFA/pull/178)
19
- - feat: support GraphQL Interfaces [PR #167](https://github.com/Urigo/SOFA/pull/167)
20
-
21
- ### v0.5.1
22
-
23
- - fix: do not skip falsy values (only null and undefined) [PR #134](https://github.com/Urigo/SOFA/pull/134)
24
-
25
- ### v0.5.0
26
-
27
- - feat(swagger): add description [PR #107](https://github.com/Urigo/SOFA/pull/107)
28
- - feat(swagger): add `ID` scalar definition [PR #107](https://github.com/Urigo/SOFA/pull/107)
29
- - fix(swagger): use `requestBody` or `parameters` not both [PR #107](https://github.com/Urigo/SOFA/pull/107)
30
- - fix(swagger): generate valid YAML structure for nested objects [PR #107](https://github.com/Urigo/SOFA/pull/107)
31
- - fix(swagger): avoid empty `required` array [PR #107](https://github.com/Urigo/SOFA/pull/107)
32
-
33
- ### v0.4.0
34
-
35
- - feat: add error handler [PR #44](https://github.com/Urigo/SOFA/pull/44) [PR #45](https://github.com/Urigo/SOFA/pull/45)
36
- - feat: allow to customize endpoint's HTTP Method [PR #46](https://github.com/Urigo/SOFA/pull/46)
37
- - feat: add InputTypeObjects to OpenAPI generation [PR #34](https://github.com/Urigo/SOFA/pull/34) - [@hajnalben](https://github.com/hajnalben)
38
-
39
- ### v0.3.0
40
-
41
- - fix: parse InputTypeObject with JSON.parse [PR #30](https://github.com/Urigo/SOFA/pull/30)
42
- - feat: custom `depthLimit` (circular references) [PR #29](https://github.com/Urigo/SOFA/pull/29)
43
-
44
- ### v0.2.3
45
-
46
- - fix: prevent circular references [PR #23](https://github.com/Urigo/SOFA/pull/23)
47
-
48
- ### v0.2.2
49
-
50
- We didn't track changes before this version.
package/bob.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = {};
package/bump.js DELETED
@@ -1,18 +0,0 @@
1
- const semver = require('semver');
2
- const packageJson = require('./package.json');
3
- const fs = require('fs');
4
- const cp = require('child_process');
5
-
6
- const gitHash = cp
7
- .spawnSync('git', ['rev-parse', '--short', 'HEAD'])
8
- .stdout.toString()
9
- .trim();
10
- const alphaVersion = semver.inc(
11
- packageJson.version,
12
- 'prerelease',
13
- true,
14
- gitHash
15
- );
16
- packageJson.version = alphaVersion;
17
-
18
- fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2));
package/dist/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Uri Goldshtein
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- import * as http from 'http';
3
- import type { ContextValue } from './types';
4
- import type { SofaConfig } from './sofa';
5
- import { ServerAdapter } from '@whatwg-node/server';
6
- export { OpenAPI } from './open-api';
7
- export declare type ContextFn = (init: {
8
- req: any;
9
- res: any;
10
- }) => ContextValue;
11
- export declare function isContextFn(context: any): context is ContextFn;
12
- interface SofaMiddlewareConfig extends SofaConfig {
13
- context?: ContextValue | ContextFn;
14
- }
15
- export declare function useSofa({ context, ...config }: SofaMiddlewareConfig): ServerAdapter<http.IncomingMessage, http.ServerResponse>;
16
- export declare function createSofaRouter(config: SofaConfig): import("itty-router").Router<import("itty-router").Request, {}>;
package/dist/package.json DELETED
@@ -1,56 +0,0 @@
1
- {
2
- "name": "sofa-api",
3
- "version": "0.11.1",
4
- "description": "Create REST APIs with GraphQL",
5
- "sideEffects": false,
6
- "peerDependencies": {
7
- "graphql": "^0.13.2 || ^14.0.0 || ^15.0.0 || ^16.0.0"
8
- },
9
- "dependencies": {
10
- "@graphql-tools/utils": "8.8.0",
11
- "@types/js-yaml": "4.0.5",
12
- "@whatwg-node/fetch": "^0.0.2",
13
- "@whatwg-node/server": "^0.0.2",
14
- "ansi-colors": "4.1.3",
15
- "itty-router": "^2.6.1",
16
- "js-yaml": "4.1.0",
17
- "param-case": "3.0.4",
18
- "title-case": "3.0.3",
19
- "trouter": "3.2.0",
20
- "tslib": "2.4.0",
21
- "uuid": "8.3.2"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "Urigo/sofa"
26
- },
27
- "keywords": [
28
- "api",
29
- "rest",
30
- "graphql",
31
- "sofa"
32
- ],
33
- "author": {
34
- "name": "Uri Goldshtein",
35
- "email": "uri.goldshtein@gmail.com",
36
- "url": "https://github.com/Urigo"
37
- },
38
- "license": "MIT",
39
- "main": "index.js",
40
- "module": "index.mjs",
41
- "typings": "index.d.ts",
42
- "typescript": {
43
- "definition": "index.d.ts"
44
- },
45
- "exports": {
46
- ".": {
47
- "require": "./index.js",
48
- "import": "./index.mjs"
49
- },
50
- "./*": {
51
- "require": "./*.js",
52
- "import": "./*.mjs"
53
- },
54
- "./package.json": "./package.json"
55
- }
56
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "CommonJS"
5
- },
6
- "include": ["example"]
7
- }