@suss/contract-graphql 0.36.0 → 0.37.1

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.
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  SCALAR_SHAPES: () => SCALAR_SHAPES,
34
+ declaredValueTypes: () => declaredValueTypes,
34
35
  describesOperations: () => describesOperations,
35
36
  describesTypes: () => describesTypes,
36
37
  graphqlDocumentFilesToSummaries: () => graphqlDocumentFilesToSummaries,
@@ -113,6 +114,47 @@ function definitionKinds(text) {
113
114
  return [];
114
115
  }
115
116
  }
117
+ var VALUE_TYPE_READERS = {
118
+ [import_graphql.Kind.ENUM_TYPE_DEFINITION]: enumOf,
119
+ [import_graphql.Kind.ENUM_TYPE_EXTENSION]: enumOf,
120
+ [import_graphql.Kind.UNION_TYPE_DEFINITION]: unionOf,
121
+ [import_graphql.Kind.UNION_TYPE_EXTENSION]: unionOf,
122
+ [import_graphql.Kind.SCALAR_TYPE_DEFINITION]: () => ({ kind: "scalar", members: [] }),
123
+ [import_graphql.Kind.SCALAR_TYPE_EXTENSION]: () => ({ kind: "scalar", members: [] })
124
+ };
125
+ function enumOf(node) {
126
+ const values = node.values ?? [];
127
+ return { kind: "enum", members: values.map((value) => value.name.value) };
128
+ }
129
+ function unionOf(node) {
130
+ const types = node.types ?? [];
131
+ return { kind: "union", members: types.map((type) => type.name.value) };
132
+ }
133
+ function declaredValueTypes(sdl) {
134
+ let doc;
135
+ try {
136
+ doc = (0, import_graphql.parse)(sdl);
137
+ } catch {
138
+ return [];
139
+ }
140
+ const found = /* @__PURE__ */ new Map();
141
+ for (const node of doc.definitions) {
142
+ const read = VALUE_TYPE_READERS[node.kind];
143
+ if (read === void 0) {
144
+ continue;
145
+ }
146
+ const valueNode = node;
147
+ const { kind, members } = read(valueNode);
148
+ const name = valueNode.name.value;
149
+ const known = found.get(name);
150
+ found.set(name, {
151
+ name,
152
+ kind,
153
+ members: [...known?.members ?? [], ...members]
154
+ });
155
+ }
156
+ return [...found.values()];
157
+ }
116
158
 
117
159
  // src/documents.ts
118
160
  var import_node_fs = __toESM(require("fs"), 1);
@@ -575,7 +617,10 @@ function buildResolverSummary(rootType, field, settings, definitions) {
575
617
  kind: "resolver",
576
618
  location: {
577
619
  file: `${source}:${ownerKey}`,
578
- range: { start: 0, end: 0 },
620
+ range: {
621
+ start: field.loc?.startToken.line ?? 0,
622
+ end: field.loc?.endToken.line ?? 0
623
+ },
579
624
  exportName: null
580
625
  },
581
626
  identity: {
@@ -687,6 +732,7 @@ function buildTransitions2(ownerKey, field) {
687
732
  // Annotate the CommonJS export names for ESM import in node:
688
733
  0 && (module.exports = {
689
734
  SCALAR_SHAPES,
735
+ declaredValueTypes,
690
736
  describesOperations,
691
737
  describesTypes,
692
738
  graphqlDocumentFilesToSummaries,
package/dist/index.d.cts CHANGED
@@ -67,6 +67,20 @@ declare const SCALAR_SHAPES: Record<string, TypeShape>;
67
67
  declare function describesTypes(text: string): boolean;
68
68
  /** True when the document has at least one operation. A file of fragments has none. */
69
69
  declare function describesOperations(text: string): boolean;
70
+ /** A type a schema declares that has no fields: an enum, a union or a custom scalar. */
71
+ interface DeclaredValueType {
72
+ name: string;
73
+ kind: "enum" | "union" | "scalar";
74
+ /** An enum's values or a union's member types, in the order written, extensions included. */
75
+ members: string[];
76
+ }
77
+ /**
78
+ * The enums, unions and custom scalars a schema declares. They have no
79
+ * fields, so they are not in `typeDefinitionsIn`, but a page that links
80
+ * each type name a field returns needs them. Empty when the SDL does not
81
+ * parse.
82
+ */
83
+ declare function declaredValueTypes(sdl: string): DeclaredValueType[];
70
84
 
71
85
  /**
72
86
  * Reads a plain GraphQL SDL file and writes one resolver summary for each
@@ -116,4 +130,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlSd
116
130
  */
117
131
  declare function loadSdlFile(filepath: string): string | null;
118
132
 
119
- export { type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
133
+ export { type DeclaredValueType, type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, declaredValueTypes, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,20 @@ declare const SCALAR_SHAPES: Record<string, TypeShape>;
67
67
  declare function describesTypes(text: string): boolean;
68
68
  /** True when the document has at least one operation. A file of fragments has none. */
69
69
  declare function describesOperations(text: string): boolean;
70
+ /** A type a schema declares that has no fields: an enum, a union or a custom scalar. */
71
+ interface DeclaredValueType {
72
+ name: string;
73
+ kind: "enum" | "union" | "scalar";
74
+ /** An enum's values or a union's member types, in the order written, extensions included. */
75
+ members: string[];
76
+ }
77
+ /**
78
+ * The enums, unions and custom scalars a schema declares. They have no
79
+ * fields, so they are not in `typeDefinitionsIn`, but a page that links
80
+ * each type name a field returns needs them. Empty when the SDL does not
81
+ * parse.
82
+ */
83
+ declare function declaredValueTypes(sdl: string): DeclaredValueType[];
70
84
 
71
85
  /**
72
86
  * Reads a plain GraphQL SDL file and writes one resolver summary for each
@@ -116,4 +130,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlSd
116
130
  */
117
131
  declare function loadSdlFile(filepath: string): string | null;
118
132
 
119
- export { type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
133
+ export { type DeclaredValueType, type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, declaredValueTypes, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.js CHANGED
@@ -81,6 +81,47 @@ function definitionKinds(text) {
81
81
  return [];
82
82
  }
83
83
  }
84
+ var VALUE_TYPE_READERS = {
85
+ [Kind.ENUM_TYPE_DEFINITION]: enumOf,
86
+ [Kind.ENUM_TYPE_EXTENSION]: enumOf,
87
+ [Kind.UNION_TYPE_DEFINITION]: unionOf,
88
+ [Kind.UNION_TYPE_EXTENSION]: unionOf,
89
+ [Kind.SCALAR_TYPE_DEFINITION]: () => ({ kind: "scalar", members: [] }),
90
+ [Kind.SCALAR_TYPE_EXTENSION]: () => ({ kind: "scalar", members: [] })
91
+ };
92
+ function enumOf(node) {
93
+ const values = node.values ?? [];
94
+ return { kind: "enum", members: values.map((value) => value.name.value) };
95
+ }
96
+ function unionOf(node) {
97
+ const types = node.types ?? [];
98
+ return { kind: "union", members: types.map((type) => type.name.value) };
99
+ }
100
+ function declaredValueTypes(sdl) {
101
+ let doc;
102
+ try {
103
+ doc = graphqlParse(sdl);
104
+ } catch {
105
+ return [];
106
+ }
107
+ const found = /* @__PURE__ */ new Map();
108
+ for (const node of doc.definitions) {
109
+ const read = VALUE_TYPE_READERS[node.kind];
110
+ if (read === void 0) {
111
+ continue;
112
+ }
113
+ const valueNode = node;
114
+ const { kind, members } = read(valueNode);
115
+ const name = valueNode.name.value;
116
+ const known = found.get(name);
117
+ found.set(name, {
118
+ name,
119
+ kind,
120
+ members: [...known?.members ?? [], ...members]
121
+ });
122
+ }
123
+ return [...found.values()];
124
+ }
84
125
 
85
126
  // src/documents.ts
86
127
  import fs from "fs";
@@ -550,7 +591,10 @@ function buildResolverSummary(rootType, field, settings, definitions) {
550
591
  kind: "resolver",
551
592
  location: {
552
593
  file: `${source}:${ownerKey}`,
553
- range: { start: 0, end: 0 },
594
+ range: {
595
+ start: field.loc?.startToken.line ?? 0,
596
+ end: field.loc?.endToken.line ?? 0
597
+ },
554
598
  exportName: null
555
599
  },
556
600
  identity: {
@@ -661,6 +705,7 @@ function buildTransitions2(ownerKey, field) {
661
705
  }
662
706
  export {
663
707
  SCALAR_SHAPES,
708
+ declaredValueTypes,
664
709
  describesOperations,
665
710
  describesTypes,
666
711
  graphqlDocumentFilesToSummaries,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-graphql",
3
- "version": "0.36.0",
3
+ "version": "0.37.1",
4
4
  "type": "module",
5
5
  "description": "Turn a GraphQL schema or a committed operation document into a suss contract and check it against the resolvers and clients on either side.",
6
6
  "keywords": [
@@ -47,7 +47,7 @@
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@suss/behavioral-ir": "0.36.0",
50
+ "@suss/behavioral-ir": "0.37.1",
51
51
  "graphql": "^16.8.0"
52
52
  },
53
53
  "devDependencies": {