@suss/contract-graphql 0.25.0 → 0.26.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
@@ -31,6 +31,8 @@ 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
+ describesOperations: () => describesOperations,
35
+ describesTypes: () => describesTypes,
34
36
  graphqlDocumentFilesToSummaries: () => graphqlDocumentFilesToSummaries,
35
37
  graphqlDocumentsPathToSummaries: () => graphqlDocumentsPathToSummaries,
36
38
  graphqlDocumentsToSummaries: () => graphqlDocumentsToSummaries,
@@ -81,6 +83,35 @@ function typeDefinitionsIn(doc) {
81
83
  }
82
84
  return definitions;
83
85
  }
86
+ var SCHEMA_KINDS = /* @__PURE__ */ new Set([
87
+ import_graphql.Kind.SCHEMA_DEFINITION,
88
+ import_graphql.Kind.SCHEMA_EXTENSION,
89
+ import_graphql.Kind.OBJECT_TYPE_DEFINITION,
90
+ import_graphql.Kind.OBJECT_TYPE_EXTENSION,
91
+ import_graphql.Kind.INTERFACE_TYPE_DEFINITION,
92
+ import_graphql.Kind.INTERFACE_TYPE_EXTENSION,
93
+ import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION,
94
+ import_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION,
95
+ import_graphql.Kind.ENUM_TYPE_DEFINITION,
96
+ import_graphql.Kind.ENUM_TYPE_EXTENSION,
97
+ import_graphql.Kind.UNION_TYPE_DEFINITION,
98
+ import_graphql.Kind.UNION_TYPE_EXTENSION,
99
+ import_graphql.Kind.SCALAR_TYPE_DEFINITION,
100
+ import_graphql.Kind.SCALAR_TYPE_EXTENSION
101
+ ]);
102
+ function describesTypes(text) {
103
+ return definitionKinds(text).some((kind) => SCHEMA_KINDS.has(kind));
104
+ }
105
+ function describesOperations(text) {
106
+ return definitionKinds(text).includes(import_graphql.Kind.OPERATION_DEFINITION);
107
+ }
108
+ function definitionKinds(text) {
109
+ try {
110
+ return (0, import_graphql.parse)(text).definitions.map((definition) => definition.kind);
111
+ } catch {
112
+ return [];
113
+ }
114
+ }
84
115
 
85
116
  // src/documents.ts
86
117
  var import_node_fs = __toESM(require("fs"), 1);
@@ -548,7 +579,7 @@ function buildResolverSummary(rootType, field, settings, definitions) {
548
579
  },
549
580
  inputs: buildInputs(field),
550
581
  transitions: buildTransitions2(ownerKey, field),
551
- // What each named type this field mentions stands for, so a reader
582
+ // The record behind each named type this field mentions, so a reader
552
583
  // comparing the field against an implementation has structure on
553
584
  // both sides rather than a name on one.
554
585
  ...Object.keys(definitions).length > 0 ? { definitions } : {},
@@ -649,6 +680,8 @@ function buildTransitions2(ownerKey, field) {
649
680
  // Annotate the CommonJS export names for ESM import in node:
650
681
  0 && (module.exports = {
651
682
  SCALAR_SHAPES,
683
+ describesOperations,
684
+ describesTypes,
652
685
  graphqlDocumentFilesToSummaries,
653
686
  graphqlDocumentsPathToSummaries,
654
687
  graphqlDocumentsToSummaries,
package/dist/index.d.cts CHANGED
@@ -52,6 +52,10 @@ declare function graphqlDocumentsPathToSummaries(specPath: string, options?: Gra
52
52
  * its own spelling can build on this table instead of restating it.
53
53
  */
54
54
  declare const SCALAR_SHAPES: Record<string, TypeShape>;
55
+ /** Whether a document declares types. A document that does is a schema. */
56
+ declare function describesTypes(text: string): boolean;
57
+ /** Whether a document has an operation to read, rather than fragments alone. */
58
+ declare function describesOperations(text: string): boolean;
55
59
 
56
60
  interface GraphqlContractOptions {
57
61
  /**
@@ -95,4 +99,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlCo
95
99
  */
96
100
  declare function loadSdlFile(filepath: string): string | null;
97
101
 
98
- export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
102
+ export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.d.ts CHANGED
@@ -52,6 +52,10 @@ declare function graphqlDocumentsPathToSummaries(specPath: string, options?: Gra
52
52
  * its own spelling can build on this table instead of restating it.
53
53
  */
54
54
  declare const SCALAR_SHAPES: Record<string, TypeShape>;
55
+ /** Whether a document declares types. A document that does is a schema. */
56
+ declare function describesTypes(text: string): boolean;
57
+ /** Whether a document has an operation to read, rather than fragments alone. */
58
+ declare function describesOperations(text: string): boolean;
55
59
 
56
60
  interface GraphqlContractOptions {
57
61
  /**
@@ -95,4 +99,4 @@ declare function graphqlSdlFileToSummaries(filepath: string, options?: GraphqlCo
95
99
  */
96
100
  declare function loadSdlFile(filepath: string): string | null;
97
101
 
98
- export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
102
+ export { type GraphqlContractOptions, type GraphqlDocumentsOptions, SCALAR_SHAPES, describesOperations, describesTypes, graphqlDocumentFilesToSummaries, graphqlDocumentsPathToSummaries, graphqlDocumentsToSummaries, graphqlSdlFileToSummaries, graphqlSdlToSummaries, loadSdlFile };
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import {
12
12
 
13
13
  // src/typeShape.ts
14
14
  import {
15
+ parse as graphqlParse,
15
16
  Kind
16
17
  } from "graphql";
17
18
  var SCALAR_SHAPES = {
@@ -50,6 +51,35 @@ function typeDefinitionsIn(doc) {
50
51
  }
51
52
  return definitions;
52
53
  }
54
+ var SCHEMA_KINDS = /* @__PURE__ */ new Set([
55
+ Kind.SCHEMA_DEFINITION,
56
+ Kind.SCHEMA_EXTENSION,
57
+ Kind.OBJECT_TYPE_DEFINITION,
58
+ Kind.OBJECT_TYPE_EXTENSION,
59
+ Kind.INTERFACE_TYPE_DEFINITION,
60
+ Kind.INTERFACE_TYPE_EXTENSION,
61
+ Kind.INPUT_OBJECT_TYPE_DEFINITION,
62
+ Kind.INPUT_OBJECT_TYPE_EXTENSION,
63
+ Kind.ENUM_TYPE_DEFINITION,
64
+ Kind.ENUM_TYPE_EXTENSION,
65
+ Kind.UNION_TYPE_DEFINITION,
66
+ Kind.UNION_TYPE_EXTENSION,
67
+ Kind.SCALAR_TYPE_DEFINITION,
68
+ Kind.SCALAR_TYPE_EXTENSION
69
+ ]);
70
+ function describesTypes(text) {
71
+ return definitionKinds(text).some((kind) => SCHEMA_KINDS.has(kind));
72
+ }
73
+ function describesOperations(text) {
74
+ return definitionKinds(text).includes(Kind.OPERATION_DEFINITION);
75
+ }
76
+ function definitionKinds(text) {
77
+ try {
78
+ return graphqlParse(text).definitions.map((definition) => definition.kind);
79
+ } catch {
80
+ return [];
81
+ }
82
+ }
53
83
 
54
84
  // src/documents.ts
55
85
  import fs from "fs";
@@ -524,7 +554,7 @@ function buildResolverSummary(rootType, field, settings, definitions) {
524
554
  },
525
555
  inputs: buildInputs(field),
526
556
  transitions: buildTransitions2(ownerKey, field),
527
- // What each named type this field mentions stands for, so a reader
557
+ // The record behind each named type this field mentions, so a reader
528
558
  // comparing the field against an implementation has structure on
529
559
  // both sides rather than a name on one.
530
560
  ...Object.keys(definitions).length > 0 ? { definitions } : {},
@@ -624,6 +654,8 @@ function buildTransitions2(ownerKey, field) {
624
654
  }
625
655
  export {
626
656
  SCALAR_SHAPES,
657
+ describesOperations,
658
+ describesTypes,
627
659
  graphqlDocumentFilesToSummaries,
628
660
  graphqlDocumentsPathToSummaries,
629
661
  graphqlDocumentsToSummaries,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-graphql",
3
- "version": "0.25.0",
3
+ "version": "0.26.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.25.0",
50
+ "@suss/behavioral-ir": "0.26.0",
51
51
  "graphql": "^16.8.0"
52
52
  },
53
53
  "devDependencies": {