sofa-api 0.15.4 → 0.15.5

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 +9 -4
  2. package/index.mjs +9 -4
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -579,6 +579,7 @@ function isContextFn(context) {
579
579
  // they might represent an Object that is not a model
580
580
  // We check it later, when an operation is being built
581
581
  function extractsModels(schema) {
582
+ var _a, _b;
582
583
  const modelMap = {};
583
584
  const query = schema.getQueryType();
584
585
  const fields = query.getFields();
@@ -598,7 +599,7 @@ function extractsModels(schema) {
598
599
  // add to registry with `list: true`
599
600
  const sameName = isNameEqual(field.name, namedType.name + 's');
600
601
  const allOptionalArguments = !field.args.some((arg) => graphql.isNonNullType(arg.type));
601
- modelMap[namedType.name].list = sameName && allOptionalArguments;
602
+ (_a = modelMap[namedType.name]).list || (_a.list = sameName && allOptionalArguments);
602
603
  }
603
604
  else if (graphql.isObjectType(field.type) ||
604
605
  (graphql.isNonNullType(field.type) && graphql.isObjectType(field.type.ofType))) {
@@ -608,7 +609,7 @@ function extractsModels(schema) {
608
609
  // add to registry with `single: true`
609
610
  const sameName = isNameEqual(field.name, namedType.name);
610
611
  const hasIdArgument = field.args.length === 1 && field.args[0].name === 'id';
611
- modelMap[namedType.name].single = sameName && hasIdArgument;
612
+ (_b = modelMap[namedType.name]).single || (_b.single = sameName && hasIdArgument);
612
613
  }
613
614
  }
614
615
  }
@@ -715,20 +716,24 @@ function buildPathFromOperation({ url, schema, operation, useRequestBody, tags,
715
716
  const info = getOperationInfo(operation);
716
717
  const enumTypes = resolveEnumTypes(schema);
717
718
  const summary = resolveDescription(schema, info.operation);
719
+ const variables = info.operation.variableDefinitions;
720
+ const pathParams = variables === null || variables === void 0 ? void 0 : variables.filter((variable) => isInPath(url, variable.variable.name.value));
721
+ const bodyParams = variables === null || variables === void 0 ? void 0 : variables.filter((variable) => !isInPath(url, variable.variable.name.value));
718
722
  return Object.assign(Object.assign({ tags,
719
723
  description,
720
724
  summary, operationId: info.name }, (useRequestBody
721
725
  ? {
726
+ parameters: resolveParameters(url, pathParams, schema, info.operation, { customScalars, enumTypes }),
722
727
  requestBody: {
723
728
  content: {
724
729
  'application/json': {
725
- schema: resolveRequestBody(info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }),
730
+ schema: resolveRequestBody(bodyParams, schema, info.operation, { customScalars, enumTypes }),
726
731
  },
727
732
  },
728
733
  },
729
734
  }
730
735
  : {
731
- parameters: resolveParameters(url, info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }),
736
+ parameters: resolveParameters(url, variables, schema, info.operation, { customScalars, enumTypes }),
732
737
  })), { responses: {
733
738
  200: {
734
739
  description: summary,
package/index.mjs CHANGED
@@ -573,6 +573,7 @@ function isContextFn(context) {
573
573
  // they might represent an Object that is not a model
574
574
  // We check it later, when an operation is being built
575
575
  function extractsModels(schema) {
576
+ var _a, _b;
576
577
  const modelMap = {};
577
578
  const query = schema.getQueryType();
578
579
  const fields = query.getFields();
@@ -592,7 +593,7 @@ function extractsModels(schema) {
592
593
  // add to registry with `list: true`
593
594
  const sameName = isNameEqual(field.name, namedType.name + 's');
594
595
  const allOptionalArguments = !field.args.some((arg) => isNonNullType(arg.type));
595
- modelMap[namedType.name].list = sameName && allOptionalArguments;
596
+ (_a = modelMap[namedType.name]).list || (_a.list = sameName && allOptionalArguments);
596
597
  }
597
598
  else if (isObjectType(field.type) ||
598
599
  (isNonNullType(field.type) && isObjectType(field.type.ofType))) {
@@ -602,7 +603,7 @@ function extractsModels(schema) {
602
603
  // add to registry with `single: true`
603
604
  const sameName = isNameEqual(field.name, namedType.name);
604
605
  const hasIdArgument = field.args.length === 1 && field.args[0].name === 'id';
605
- modelMap[namedType.name].single = sameName && hasIdArgument;
606
+ (_b = modelMap[namedType.name]).single || (_b.single = sameName && hasIdArgument);
606
607
  }
607
608
  }
608
609
  }
@@ -709,20 +710,24 @@ function buildPathFromOperation({ url, schema, operation, useRequestBody, tags,
709
710
  const info = getOperationInfo(operation);
710
711
  const enumTypes = resolveEnumTypes(schema);
711
712
  const summary = resolveDescription(schema, info.operation);
713
+ const variables = info.operation.variableDefinitions;
714
+ const pathParams = variables === null || variables === void 0 ? void 0 : variables.filter((variable) => isInPath(url, variable.variable.name.value));
715
+ const bodyParams = variables === null || variables === void 0 ? void 0 : variables.filter((variable) => !isInPath(url, variable.variable.name.value));
712
716
  return Object.assign(Object.assign({ tags,
713
717
  description,
714
718
  summary, operationId: info.name }, (useRequestBody
715
719
  ? {
720
+ parameters: resolveParameters(url, pathParams, schema, info.operation, { customScalars, enumTypes }),
716
721
  requestBody: {
717
722
  content: {
718
723
  'application/json': {
719
- schema: resolveRequestBody(info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }),
724
+ schema: resolveRequestBody(bodyParams, schema, info.operation, { customScalars, enumTypes }),
720
725
  },
721
726
  },
722
727
  },
723
728
  }
724
729
  : {
725
- parameters: resolveParameters(url, info.operation.variableDefinitions, schema, info.operation, { customScalars, enumTypes }),
730
+ parameters: resolveParameters(url, variables, schema, info.operation, { customScalars, enumTypes }),
726
731
  })), { responses: {
727
732
  200: {
728
733
  description: summary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sofa-api",
3
- "version": "0.15.4",
3
+ "version": "0.15.5",
4
4
  "description": "Create REST APIs with GraphQL",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {