@awsless/awsless 0.0.191 → 0.0.193

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 (2) hide show
  1. package/dist/bin.js +40 -79
  2. package/package.json +4 -4
package/dist/bin.js CHANGED
@@ -2516,7 +2516,7 @@ var functionFeature = defineFeature({
2516
2516
  import { paramCase as paramCase5 } from "change-case";
2517
2517
  import { mergeTypeDefs } from "@graphql-tools/merge";
2518
2518
  import { generate } from "@awsless/graphql";
2519
- import { buildSchema, isObjectType, print } from "graphql";
2519
+ import { buildSchema, print } from "graphql";
2520
2520
  import { readFile as readFile5 } from "fs/promises";
2521
2521
  import { Asset as Asset2, Node as Node6, aws as aws6 } from "@awsless/formation";
2522
2522
 
@@ -2751,28 +2751,10 @@ var graphqlFeature = defineFeature({
2751
2751
  onApp(ctx) {
2752
2752
  for (const [id, props] of Object.entries(ctx.appConfig.defaults.graphql ?? {})) {
2753
2753
  const group = new Node6(ctx.base, "graphql", id);
2754
- const role = new aws6.iam.Role(group, "role", {
2755
- assumedBy: "appsync.amazonaws.com",
2756
- policies: [
2757
- {
2758
- name: "merge-policy",
2759
- statements: [
2760
- {
2761
- actions: [
2762
- //
2763
- "appsync:StartSchemaMerge",
2764
- "appsync:SourceGraphQL"
2765
- ],
2766
- resources: [`arn:aws:appsync:${ctx.appConfig.region}:${ctx.accountId}:apis/*`]
2767
- }
2768
- ]
2769
- }
2770
- ]
2771
- });
2754
+ const name = formatGlobalResourceName(ctx.app.name, "graphql", id);
2772
2755
  const api = new aws6.appsync.GraphQLApi(group, "api", {
2773
- name: formatGlobalResourceName(ctx.app.name, "graphql", id),
2774
- type: "merged",
2775
- role: role.arn,
2756
+ name,
2757
+ type: "graphql",
2776
2758
  auth: {
2777
2759
  default: props.auth ? {
2778
2760
  type: "cognito",
@@ -2784,6 +2766,32 @@ var graphqlFeature = defineFeature({
2784
2766
  }
2785
2767
  });
2786
2768
  ctx.shared.set(`graphql-${id}-id`, api.id);
2769
+ ctx.registerBuild("graphql-schema", name, async (build3) => {
2770
+ const sources = [];
2771
+ const fingers = [];
2772
+ for (const stack of ctx.stackConfigs) {
2773
+ const file = stack.graphql?.[id]?.schema;
2774
+ if (file) {
2775
+ const source = await readFile5(file, "utf8");
2776
+ const finger2 = createHash4("sha1").update(source).digest("hex");
2777
+ sources.push(source);
2778
+ fingers.push(finger2);
2779
+ }
2780
+ }
2781
+ const finger = createHash4("sha1").update(sources.sort().join(" ")).digest("hex");
2782
+ return build3(finger, async (write) => {
2783
+ const defs = mergeTypeDefs([scalarSchema, baseSchema, ...sources]);
2784
+ const output = print(defs);
2785
+ await write("schema.gql", output);
2786
+ return {
2787
+ size: formatByteSize(Buffer.from(output).byteLength)
2788
+ };
2789
+ });
2790
+ });
2791
+ new aws6.appsync.GraphQLSchema(group, "schema", {
2792
+ apiId: api.id,
2793
+ definition: Asset2.fromFile(getBuildPath("graphql-schema", name, "schema.gql"))
2794
+ });
2787
2795
  if (props.resolver) {
2788
2796
  ctx.registerBuild("graphql-resolver", id, async (build3) => {
2789
2797
  const resolver = props.resolver;
@@ -2834,57 +2842,11 @@ var graphqlFeature = defineFeature({
2834
2842
  );
2835
2843
  }
2836
2844
  const group = new Node6(ctx.stack, "graphql", id);
2837
- const name = formatLocalResourceName(ctx.app.name, ctx.stack.name, "graphql", id);
2838
- const api = new aws6.appsync.GraphQLApi(group, "api", {
2839
- name,
2840
- // visibility: false,
2841
- auth: {
2842
- default: {
2843
- type: "iam"
2844
- }
2845
- }
2846
- });
2847
- ctx.registerBuild("graphql-schema", name, async (build3) => {
2848
- const source = await readFile5(props.schema, "utf8");
2849
- const finger = createHash4("sha1").update(source).digest("hex");
2850
- return build3(finger, async (write) => {
2851
- const defs = mergeTypeDefs([scalarSchema, baseSchema, source]);
2852
- const output = print(defs);
2853
- const schema2 = buildSchema(output);
2854
- for (const [typeName, fields] of Object.entries(props.resolvers ?? {})) {
2855
- const type = schema2.getType(typeName);
2856
- if (!type || !isObjectType(type)) {
2857
- throw new FileError(props.schema, `GraphQL schema type doesn't exist: ${typeName}`);
2858
- }
2859
- const typeFields = type.getFields();
2860
- for (const fieldName of Object.keys(fields ?? {})) {
2861
- if (!(fieldName in typeFields)) {
2862
- throw new FileError(
2863
- props.schema,
2864
- `GraphQL schema field doesn't exist: ${typeName}.${fieldName}`
2865
- );
2866
- }
2867
- }
2868
- }
2869
- await write("schema.gql", output);
2870
- return {
2871
- size: formatByteSize(Buffer.from(source).byteLength)
2872
- };
2873
- });
2874
- });
2875
- const schema = new aws6.appsync.GraphQLSchema(group, "schema", {
2876
- apiId: api.id,
2877
- definition: Asset2.fromFile(getBuildPath("graphql-schema", name, "schema.gql"))
2878
- });
2879
- const association = new aws6.appsync.SourceApiAssociation(group, "association", {
2880
- mergedApiId: ctx.shared.get(`graphql-${id}-id`),
2881
- sourceApiId: api.id
2882
- });
2883
- association.dependsOn(schema);
2845
+ const apiId = ctx.shared.get(`graphql-${id}-id`);
2884
2846
  for (const [typeName, fields] of Object.entries(props.resolvers ?? {})) {
2885
2847
  for (const [fieldName, props2] of Object.entries(fields ?? {})) {
2886
- const name2 = `${typeName}__${fieldName}`;
2887
- const resolverGroup = new Node6(group, "resolver", name2);
2848
+ const name = `${typeName}__${fieldName}`;
2849
+ const resolverGroup = new Node6(group, "resolver", name);
2888
2850
  const entryId = paramCase5(`${id}-${typeName}-${fieldName}`);
2889
2851
  const { lambda } = createLambdaFunction(resolverGroup, ctx, `graphql`, entryId, {
2890
2852
  ...props2.consumer,
@@ -2905,10 +2867,10 @@ var graphqlFeature = defineFeature({
2905
2867
  ]
2906
2868
  });
2907
2869
  const source = new aws6.appsync.DataSource(resolverGroup, "source", {
2908
- apiId: api.id,
2909
- type: "lambda",
2910
- name: name2,
2870
+ apiId,
2871
+ name,
2911
2872
  role: role.arn,
2873
+ type: "lambda",
2912
2874
  functionArn: lambda.arn
2913
2875
  });
2914
2876
  let code = Asset2.fromString(defaultResolver);
@@ -2918,19 +2880,18 @@ var graphqlFeature = defineFeature({
2918
2880
  code = Asset2.fromFile(getBuildPath("graphql-resolver", id, "resolver.js"));
2919
2881
  }
2920
2882
  const config2 = new aws6.appsync.FunctionConfiguration(resolverGroup, "config", {
2921
- apiId: api.id,
2922
- name: name2,
2883
+ apiId,
2884
+ name,
2923
2885
  code,
2924
2886
  dataSourceName: source.name
2925
2887
  });
2926
- const resolver = new aws6.appsync.Resolver(resolverGroup, "resolver", {
2927
- apiId: api.id,
2888
+ new aws6.appsync.Resolver(resolverGroup, "resolver", {
2889
+ apiId,
2928
2890
  typeName,
2929
2891
  fieldName,
2930
2892
  functions: [config2.id],
2931
2893
  code
2932
2894
  });
2933
- resolver.dependsOn(schema);
2934
2895
  }
2935
2896
  }
2936
2897
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.191",
3
+ "version": "0.0.193",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -29,12 +29,12 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@awsless/lambda": "^0.0.18",
32
- "@awsless/s3": "^0.0.10",
33
32
  "@awsless/redis": "^0.0.12",
33
+ "@awsless/s3": "^0.0.10",
34
34
  "@awsless/sns": "^0.0.7",
35
35
  "@awsless/sqs": "^0.0.7",
36
- "@awsless/ssm": "^0.0.7",
37
36
  "@awsless/validate": "^0.0.13",
37
+ "@awsless/ssm": "^0.0.7",
38
38
  "@awsless/weak-cache": "^0.0.1"
39
39
  },
40
40
  "dependencies": {
@@ -97,9 +97,9 @@
97
97
  "zod": "^3.21.4",
98
98
  "zod-to-json-schema": "^3.22.3",
99
99
  "@awsless/duration": "^0.0.1",
100
+ "@awsless/formation": "^0.0.14",
100
101
  "@awsless/graphql": "^0.0.9",
101
102
  "@awsless/size": "^0.0.1",
102
- "@awsless/formation": "^0.0.13",
103
103
  "@awsless/validate": "^0.0.13",
104
104
  "@awsless/code": "^0.0.10"
105
105
  },