sofa-api 0.13.0 → 0.14.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 (3) hide show
  1. package/index.js +11 -7
  2. package/index.mjs +11 -7
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -367,7 +367,7 @@ function createRouter(sofa) {
367
367
  return router;
368
368
  }
369
369
  function createQueryRoute({ sofa, router, fieldName, }) {
370
- var _a, _b, _c, _d, _e, _f;
370
+ var _a, _b, _c, _d, _e, _f, _g;
371
371
  logger.debug(`[Router] Creating ${fieldName} query`);
372
372
  const queryType = sofa.schema.getQueryType();
373
373
  const operationNode = utils.buildOperationNodeForField({
@@ -402,13 +402,14 @@ function createQueryRoute({ sofa, router, fieldName, }) {
402
402
  path: route.path,
403
403
  method: route.method.toUpperCase(),
404
404
  tags: (_e = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.tags) !== null && _e !== void 0 ? _e : [],
405
- description: (_f = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _f !== void 0 ? _f : '',
405
+ description: (_g = (_f = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _f !== void 0 ? _f : field.description) !== null && _g !== void 0 ? _g : '',
406
406
  };
407
407
  }
408
408
  function createMutationRoute({ sofa, router, fieldName, }) {
409
- var _a, _b, _c, _d;
409
+ var _a, _b, _c, _d, _e, _f;
410
410
  logger.debug(`[Router] Creating ${fieldName} mutation`);
411
411
  const mutationType = sofa.schema.getMutationType();
412
+ const field = mutationType.getFields()[fieldName];
412
413
  const operationNode = utils.buildOperationNodeForField({
413
414
  kind: 'mutation',
414
415
  schema: sofa.schema,
@@ -437,7 +438,7 @@ function createMutationRoute({ sofa, router, fieldName, }) {
437
438
  path,
438
439
  method,
439
440
  tags: (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.tags) || [],
440
- description: (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) || '',
441
+ description: (_f = (_e = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _e !== void 0 ? _e : field.description) !== null && _f !== void 0 ? _f : '',
441
442
  };
442
443
  }
443
444
  function useHandler(config) {
@@ -644,6 +645,7 @@ function resolveField(field, opts) {
644
645
  // type -> $ref
645
646
  // scalar -> swagger primitive
646
647
  function resolveFieldType(type, opts) {
648
+ var _a;
647
649
  if (graphql.isNonNullType(type)) {
648
650
  return resolveFieldType(type.ofType, opts);
649
651
  }
@@ -660,9 +662,11 @@ function resolveFieldType(type, opts) {
660
662
  }
661
663
  if (graphql.isScalarType(type)) {
662
664
  return (mapToPrimitive(type.name) ||
663
- opts.customScalars[type.name] || {
664
- type: 'object',
665
- });
665
+ opts.customScalars[type.name] ||
666
+ ((_a = type.extensions) === null || _a === void 0 ? void 0 : _a.jsonSchema)
667
+ || {
668
+ type: 'object',
669
+ });
666
670
  }
667
671
  if (graphql.isEnumType(type)) {
668
672
  return {
package/index.mjs CHANGED
@@ -361,7 +361,7 @@ function createRouter(sofa) {
361
361
  return router;
362
362
  }
363
363
  function createQueryRoute({ sofa, router, fieldName, }) {
364
- var _a, _b, _c, _d, _e, _f;
364
+ var _a, _b, _c, _d, _e, _f, _g;
365
365
  logger.debug(`[Router] Creating ${fieldName} query`);
366
366
  const queryType = sofa.schema.getQueryType();
367
367
  const operationNode = buildOperationNodeForField({
@@ -396,13 +396,14 @@ function createQueryRoute({ sofa, router, fieldName, }) {
396
396
  path: route.path,
397
397
  method: route.method.toUpperCase(),
398
398
  tags: (_e = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.tags) !== null && _e !== void 0 ? _e : [],
399
- description: (_f = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _f !== void 0 ? _f : '',
399
+ description: (_g = (_f = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _f !== void 0 ? _f : field.description) !== null && _g !== void 0 ? _g : '',
400
400
  };
401
401
  }
402
402
  function createMutationRoute({ sofa, router, fieldName, }) {
403
- var _a, _b, _c, _d;
403
+ var _a, _b, _c, _d, _e, _f;
404
404
  logger.debug(`[Router] Creating ${fieldName} mutation`);
405
405
  const mutationType = sofa.schema.getMutationType();
406
+ const field = mutationType.getFields()[fieldName];
406
407
  const operationNode = buildOperationNodeForField({
407
408
  kind: 'mutation',
408
409
  schema: sofa.schema,
@@ -431,7 +432,7 @@ function createMutationRoute({ sofa, router, fieldName, }) {
431
432
  path,
432
433
  method,
433
434
  tags: (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.tags) || [],
434
- description: (routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) || '',
435
+ description: (_f = (_e = routeConfig === null || routeConfig === void 0 ? void 0 : routeConfig.description) !== null && _e !== void 0 ? _e : field.description) !== null && _f !== void 0 ? _f : '',
435
436
  };
436
437
  }
437
438
  function useHandler(config) {
@@ -638,6 +639,7 @@ function resolveField(field, opts) {
638
639
  // type -> $ref
639
640
  // scalar -> swagger primitive
640
641
  function resolveFieldType(type, opts) {
642
+ var _a;
641
643
  if (isNonNullType(type)) {
642
644
  return resolveFieldType(type.ofType, opts);
643
645
  }
@@ -654,9 +656,11 @@ function resolveFieldType(type, opts) {
654
656
  }
655
657
  if (isScalarType(type)) {
656
658
  return (mapToPrimitive(type.name) ||
657
- opts.customScalars[type.name] || {
658
- type: 'object',
659
- });
659
+ opts.customScalars[type.name] ||
660
+ ((_a = type.extensions) === null || _a === void 0 ? void 0 : _a.jsonSchema)
661
+ || {
662
+ type: 'object',
663
+ });
660
664
  }
661
665
  if (isEnumType(type)) {
662
666
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sofa-api",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Create REST APIs with GraphQL",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {