@suss/contract-graphql 0.34.1 → 0.35.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.
package/dist/index.cjs CHANGED
@@ -44,6 +44,7 @@ module.exports = __toCommonJS(index_exports);
44
44
  var import_node_fs2 = __toESM(require("fs"), 1);
45
45
  var import_graphql3 = require("graphql");
46
46
  var import_behavioral_ir2 = require("@suss/behavioral-ir");
47
+ var import_files2 = require("@suss/behavioral-ir/files");
47
48
 
48
49
  // src/typeShape.ts
49
50
  var import_graphql = require("graphql");
@@ -118,6 +119,7 @@ var import_node_fs = __toESM(require("fs"), 1);
118
119
  var import_node_path = __toESM(require("path"), 1);
119
120
  var import_graphql2 = require("graphql");
120
121
  var import_behavioral_ir = require("@suss/behavioral-ir");
122
+ var import_files = require("@suss/behavioral-ir/files");
121
123
  function graphqlDocumentsToSummaries(sources, options = {}) {
122
124
  const recognition = options.recognition ?? "graphql-documents";
123
125
  const transport = options.transport ?? "http-graphql";
@@ -179,6 +181,8 @@ function distinctName(candidate, taken) {
179
181
  return name;
180
182
  }
181
183
  function graphqlDocumentFilesToSummaries(filepaths, options = {}) {
184
+ const { projectRoot, rootDir, ...documentOptions } = options;
185
+ const root = projectRoot ?? (0, import_files.defaultProjectRoot)(rootDir ?? filepaths[0] ?? ".");
182
186
  const sources = [];
183
187
  for (const filepath of filepaths) {
184
188
  let text;
@@ -187,9 +191,13 @@ function graphqlDocumentFilesToSummaries(filepaths, options = {}) {
187
191
  } catch {
188
192
  continue;
189
193
  }
190
- sources.push({ path: filepath, text });
194
+ sources.push({ path: (0, import_files.pathInProject)(filepath, root), text });
191
195
  }
192
- return graphqlDocumentsToSummaries(sources, options);
196
+ return graphqlDocumentsToSummaries(sources, {
197
+ ...documentOptions,
198
+ // An anonymous operation is named from rootDir, so both are spelled from one root.
199
+ ...rootDir === void 0 ? {} : { rootDir: (0, import_files.pathInProject)(rootDir, root) }
200
+ });
193
201
  }
194
202
  function graphqlDocumentsPathToSummaries(specPath, options = {}) {
195
203
  const absolute = import_node_path.default.resolve(specPath);
@@ -511,9 +519,13 @@ function graphqlSdlToSummaries(sdl, options = {}) {
511
519
  }
512
520
  function graphqlSdlFileToSummaries(filepath, options = {}) {
513
521
  const sdl = import_node_fs2.default.readFileSync(filepath, "utf8");
522
+ const { projectRoot, ...contractOptions } = options;
514
523
  return graphqlSdlToSummaries(sdl, {
515
- source: filepath,
516
- ...options
524
+ source: (0, import_files2.pathInProject)(
525
+ filepath,
526
+ projectRoot ?? (0, import_files2.defaultProjectRoot)(filepath)
527
+ ),
528
+ ...contractOptions
517
529
  });
518
530
  }
519
531
  function loadSdlFile(filepath) {
package/dist/index.d.cts CHANGED
@@ -23,8 +23,9 @@ interface GraphqlDocumentsOptions {
23
23
  */
24
24
  transport?: string;
25
25
  /**
26
- * The directory an anonymous operation's name is relative to, so the
27
- * name is the same on every machine. Without it the path is used as is.
26
+ * The directory an anonymous operation's name is relative to, spelled
27
+ * the way the sources' paths are, so the name is the same on every
28
+ * machine. Without it the path is used as is.
28
29
  */
29
30
  rootDir?: string;
30
31
  }
@@ -40,17 +41,21 @@ interface DocumentSource {
40
41
  * contributes definitions but does not produce a summary.
41
42
  */
42
43
  declare function graphqlDocumentsToSummaries(sources: DocumentSource[], options?: GraphqlDocumentsOptions): BehavioralSummary[];
44
+ interface GraphqlDocumentFilesOptions extends GraphqlDocumentsOptions {
45
+ /** Absolute. The directory each file's path is measured from. */
46
+ projectRoot?: string;
47
+ }
43
48
  /**
44
49
  * Reads `.graphql` and `.gql` files and converts them. A file that cannot
45
50
  * be read is skipped, so one bad path does not lose the rest.
46
51
  */
47
- declare function graphqlDocumentFilesToSummaries(filepaths: string[], options?: GraphqlDocumentsOptions): BehavioralSummary[];
52
+ declare function graphqlDocumentFilesToSummaries(filepaths: string[], options?: GraphqlDocumentFilesOptions): BehavioralSummary[];
48
53
  /**
49
54
  * Reads one document file, or every `.graphql` and `.gql` file under a
50
55
  * directory, skipping `node_modules`. Throws when nothing exists at the
51
56
  * path. `suss contract --from graphql-documents <path>` calls this.
52
57
  */
53
- declare function graphqlDocumentsPathToSummaries(specPath: string, options?: GraphqlDocumentsOptions): BehavioralSummary[];
58
+ declare function graphqlDocumentsPathToSummaries(specPath: string, options?: GraphqlDocumentFilesOptions): BehavioralSummary[];
54
59
 
55
60
  /**
56
61
  * The TypeShape for each of the five standard GraphQL scalars. A pack
@@ -94,11 +99,15 @@ interface GraphqlContractOptions {
94
99
  * does not parse or has no root fields.
95
100
  */
96
101
  declare function graphqlSdlToSummaries(sdl: string, options?: GraphqlContractOptions): BehavioralSummary[];
102
+ interface GraphqlSdlFileOptions extends GraphqlContractOptions {
103
+ /** Absolute. The directory the file's path is measured from. */
104
+ projectRoot?: string;
105
+ }
97
106
  /**
98
- * Reads an SDL file and converts it, recording the file path as the
99
- * source. `suss contract --from graphql <file>` calls this.
107
+ * Reads an SDL file and converts it, recording the file's path in its
108
+ * project as the source. `suss contract --from graphql <file>` calls this.
100
109
  */
101
- declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlContractOptions): BehavioralSummary[];
110
+ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlSdlFileOptions): BehavioralSummary[];
102
111
  /**
103
112
  * Reads an SDL file and returns its text, or `null` when the file cannot
104
113
  * be read. @suss/contract-appsync uses it for the schema file a template
@@ -107,4 +116,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlCo
107
116
  */
108
117
  declare function loadSdlFile(filepath: string): string | null;
109
118
 
110
- export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
119
+ export { type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.d.ts CHANGED
@@ -23,8 +23,9 @@ interface GraphqlDocumentsOptions {
23
23
  */
24
24
  transport?: string;
25
25
  /**
26
- * The directory an anonymous operation's name is relative to, so the
27
- * name is the same on every machine. Without it the path is used as is.
26
+ * The directory an anonymous operation's name is relative to, spelled
27
+ * the way the sources' paths are, so the name is the same on every
28
+ * machine. Without it the path is used as is.
28
29
  */
29
30
  rootDir?: string;
30
31
  }
@@ -40,17 +41,21 @@ interface DocumentSource {
40
41
  * contributes definitions but does not produce a summary.
41
42
  */
42
43
  declare function graphqlDocumentsToSummaries(sources: DocumentSource[], options?: GraphqlDocumentsOptions): BehavioralSummary[];
44
+ interface GraphqlDocumentFilesOptions extends GraphqlDocumentsOptions {
45
+ /** Absolute. The directory each file's path is measured from. */
46
+ projectRoot?: string;
47
+ }
43
48
  /**
44
49
  * Reads `.graphql` and `.gql` files and converts them. A file that cannot
45
50
  * be read is skipped, so one bad path does not lose the rest.
46
51
  */
47
- declare function graphqlDocumentFilesToSummaries(filepaths: string[], options?: GraphqlDocumentsOptions): BehavioralSummary[];
52
+ declare function graphqlDocumentFilesToSummaries(filepaths: string[], options?: GraphqlDocumentFilesOptions): BehavioralSummary[];
48
53
  /**
49
54
  * Reads one document file, or every `.graphql` and `.gql` file under a
50
55
  * directory, skipping `node_modules`. Throws when nothing exists at the
51
56
  * path. `suss contract --from graphql-documents <path>` calls this.
52
57
  */
53
- declare function graphqlDocumentsPathToSummaries(specPath: string, options?: GraphqlDocumentsOptions): BehavioralSummary[];
58
+ declare function graphqlDocumentsPathToSummaries(specPath: string, options?: GraphqlDocumentFilesOptions): BehavioralSummary[];
54
59
 
55
60
  /**
56
61
  * The TypeShape for each of the five standard GraphQL scalars. A pack
@@ -94,11 +99,15 @@ interface GraphqlContractOptions {
94
99
  * does not parse or has no root fields.
95
100
  */
96
101
  declare function graphqlSdlToSummaries(sdl: string, options?: GraphqlContractOptions): BehavioralSummary[];
102
+ interface GraphqlSdlFileOptions extends GraphqlContractOptions {
103
+ /** Absolute. The directory the file's path is measured from. */
104
+ projectRoot?: string;
105
+ }
97
106
  /**
98
- * Reads an SDL file and converts it, recording the file path as the
99
- * source. `suss contract --from graphql <file>` calls this.
107
+ * Reads an SDL file and converts it, recording the file's path in its
108
+ * project as the source. `suss contract --from graphql <file>` calls this.
100
109
  */
101
- declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlContractOptions): BehavioralSummary[];
110
+ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlSdlFileOptions): BehavioralSummary[];
102
111
  /**
103
112
  * Reads an SDL file and returns its text, or `null` when the file cannot
104
113
  * be read. @suss/contract-appsync uses it for the schema file a template
@@ -107,4 +116,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlCo
107
116
  */
108
117
  declare function loadSdlFile(filepath: string): string | null;
109
118
 
110
- export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
119
+ export { type GraphqlContractOptions, type GraphqlDocumentFilesOptions, type GraphqlDocumentsOptions, type GraphqlSdlFileOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  withGraphqlMetadata as withGraphqlMetadata2,
10
10
  withSourceDocumentMetadata
11
11
  } from "@suss/behavioral-ir";
12
+ import { defaultProjectRoot as defaultProjectRoot2, pathInProject as pathInProject2 } from "@suss/behavioral-ir/files";
12
13
 
13
14
  // src/typeShape.ts
14
15
  import {
@@ -93,6 +94,7 @@ import {
93
94
  graphqlOperationBinding,
94
95
  withGraphqlMetadata
95
96
  } from "@suss/behavioral-ir";
97
+ import { defaultProjectRoot, pathInProject } from "@suss/behavioral-ir/files";
96
98
  function graphqlDocumentsToSummaries(sources, options = {}) {
97
99
  const recognition = options.recognition ?? "graphql-documents";
98
100
  const transport = options.transport ?? "http-graphql";
@@ -154,6 +156,8 @@ function distinctName(candidate, taken) {
154
156
  return name;
155
157
  }
156
158
  function graphqlDocumentFilesToSummaries(filepaths, options = {}) {
159
+ const { projectRoot, rootDir, ...documentOptions } = options;
160
+ const root = projectRoot ?? defaultProjectRoot(rootDir ?? filepaths[0] ?? ".");
157
161
  const sources = [];
158
162
  for (const filepath of filepaths) {
159
163
  let text;
@@ -162,9 +166,13 @@ function graphqlDocumentFilesToSummaries(filepaths, options = {}) {
162
166
  } catch {
163
167
  continue;
164
168
  }
165
- sources.push({ path: filepath, text });
169
+ sources.push({ path: pathInProject(filepath, root), text });
166
170
  }
167
- return graphqlDocumentsToSummaries(sources, options);
171
+ return graphqlDocumentsToSummaries(sources, {
172
+ ...documentOptions,
173
+ // An anonymous operation is named from rootDir, so both are spelled from one root.
174
+ ...rootDir === void 0 ? {} : { rootDir: pathInProject(rootDir, root) }
175
+ });
168
176
  }
169
177
  function graphqlDocumentsPathToSummaries(specPath, options = {}) {
170
178
  const absolute = path.resolve(specPath);
@@ -486,9 +494,13 @@ function graphqlSdlToSummaries(sdl, options = {}) {
486
494
  }
487
495
  function graphqlSdlFileToSummaries(filepath, options = {}) {
488
496
  const sdl = fs2.readFileSync(filepath, "utf8");
497
+ const { projectRoot, ...contractOptions } = options;
489
498
  return graphqlSdlToSummaries(sdl, {
490
- source: filepath,
491
- ...options
499
+ source: pathInProject2(
500
+ filepath,
501
+ projectRoot ?? defaultProjectRoot2(filepath)
502
+ ),
503
+ ...contractOptions
492
504
  });
493
505
  }
494
506
  function loadSdlFile(filepath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-graphql",
3
- "version": "0.34.1",
3
+ "version": "0.35.0",
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.34.1",
50
+ "@suss/behavioral-ir": "0.35.0",
51
51
  "graphql": "^16.8.0"
52
52
  },
53
53
  "devDependencies": {