@suss/contract-graphql 0.9.0 → 0.11.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
@@ -446,15 +446,19 @@ function graphqlSdlToSummaries(sdl, options = {}) {
446
446
  } catch (_err) {
447
447
  return [];
448
448
  }
449
- const source = options.source ?? "graphql";
450
- const recognition = options.recognition ?? "graphql";
451
- const transport = options.transport ?? "http-graphql";
452
- const out = [];
449
+ const settings = {
450
+ sdl,
451
+ source: options.source ?? "graphql",
452
+ recognition: options.recognition ?? "graphql",
453
+ transport: options.transport ?? "http-graphql"
454
+ };
453
455
  const rootFields = collectRootFields(doc);
456
+ if (rootFields.length === 0) {
457
+ return [];
458
+ }
459
+ const out = [buildSchemaDocumentSummary(settings)];
454
460
  for (const { rootType, field } of rootFields) {
455
- out.push(
456
- buildResolverSummary(rootType, field, source, recognition, transport)
457
- );
461
+ out.push(buildResolverSummary(rootType, field, settings));
458
462
  }
459
463
  return out;
460
464
  }
@@ -504,7 +508,8 @@ function collectRootFields(doc) {
504
508
  function isRootType(name) {
505
509
  return ROOT_TYPES.includes(name);
506
510
  }
507
- function buildResolverSummary(rootType, field, source, recognition, transport) {
511
+ function buildResolverSummary(rootType, field, settings) {
512
+ const { source, recognition, transport } = settings;
508
513
  const fieldName = field.name.value;
509
514
  const ownerKey = `${rootType}.${fieldName}`;
510
515
  return {
@@ -533,11 +538,30 @@ function buildResolverSummary(rootType, field, source, recognition, transport) {
533
538
  // is "derived" because both this metadata and the summary's
534
539
  // transitions come from the same SDL field declaration;
535
540
  // self-comparison would be tautological.
536
- metadata: (0, import_behavioral_ir2.withGraphqlMetadata)(void 0, {
537
- rootType,
538
- fieldName,
539
- declaredContract: buildDeclaredContract(field, recognition)
540
- })
541
+ metadata: (0, import_behavioral_ir2.withGraphqlMetadata)(
542
+ (0, import_behavioral_ir2.withSourceDocumentMetadata)(void 0, { label: source }),
543
+ {
544
+ rootType,
545
+ fieldName,
546
+ declaredContract: buildDeclaredContract(field, recognition)
547
+ }
548
+ )
549
+ };
550
+ }
551
+ function buildSchemaDocumentSummary(settings) {
552
+ const { source, sdl } = settings;
553
+ return {
554
+ kind: "library",
555
+ location: { file: source, range: { start: 0, end: 0 }, exportName: null },
556
+ identity: { name: source, exportPath: null, boundaryBinding: null },
557
+ inputs: [],
558
+ transitions: [],
559
+ gaps: [],
560
+ confidence: { source: "derived", level: "high" },
561
+ metadata: (0, import_behavioral_ir2.withGraphqlMetadata)(
562
+ (0, import_behavioral_ir2.withSourceDocumentMetadata)(void 0, { label: source }),
563
+ { schemaSdl: sdl }
564
+ )
541
565
  };
542
566
  }
543
567
  function buildDeclaredContract(field, recognition) {
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ import {
6
6
  } from "graphql";
7
7
  import {
8
8
  graphqlResolverBinding,
9
- withGraphqlMetadata as withGraphqlMetadata2
9
+ withGraphqlMetadata as withGraphqlMetadata2,
10
+ withSourceDocumentMetadata
10
11
  } from "@suss/behavioral-ir";
11
12
 
12
13
  // src/typeShape.ts
@@ -419,15 +420,19 @@ function graphqlSdlToSummaries(sdl, options = {}) {
419
420
  } catch (_err) {
420
421
  return [];
421
422
  }
422
- const source = options.source ?? "graphql";
423
- const recognition = options.recognition ?? "graphql";
424
- const transport = options.transport ?? "http-graphql";
425
- const out = [];
423
+ const settings = {
424
+ sdl,
425
+ source: options.source ?? "graphql",
426
+ recognition: options.recognition ?? "graphql",
427
+ transport: options.transport ?? "http-graphql"
428
+ };
426
429
  const rootFields = collectRootFields(doc);
430
+ if (rootFields.length === 0) {
431
+ return [];
432
+ }
433
+ const out = [buildSchemaDocumentSummary(settings)];
427
434
  for (const { rootType, field } of rootFields) {
428
- out.push(
429
- buildResolverSummary(rootType, field, source, recognition, transport)
430
- );
435
+ out.push(buildResolverSummary(rootType, field, settings));
431
436
  }
432
437
  return out;
433
438
  }
@@ -477,7 +482,8 @@ function collectRootFields(doc) {
477
482
  function isRootType(name) {
478
483
  return ROOT_TYPES.includes(name);
479
484
  }
480
- function buildResolverSummary(rootType, field, source, recognition, transport) {
485
+ function buildResolverSummary(rootType, field, settings) {
486
+ const { source, recognition, transport } = settings;
481
487
  const fieldName = field.name.value;
482
488
  const ownerKey = `${rootType}.${fieldName}`;
483
489
  return {
@@ -506,11 +512,30 @@ function buildResolverSummary(rootType, field, source, recognition, transport) {
506
512
  // is "derived" because both this metadata and the summary's
507
513
  // transitions come from the same SDL field declaration;
508
514
  // self-comparison would be tautological.
509
- metadata: withGraphqlMetadata2(void 0, {
510
- rootType,
511
- fieldName,
512
- declaredContract: buildDeclaredContract(field, recognition)
513
- })
515
+ metadata: withGraphqlMetadata2(
516
+ withSourceDocumentMetadata(void 0, { label: source }),
517
+ {
518
+ rootType,
519
+ fieldName,
520
+ declaredContract: buildDeclaredContract(field, recognition)
521
+ }
522
+ )
523
+ };
524
+ }
525
+ function buildSchemaDocumentSummary(settings) {
526
+ const { source, sdl } = settings;
527
+ return {
528
+ kind: "library",
529
+ location: { file: source, range: { start: 0, end: 0 }, exportName: null },
530
+ identity: { name: source, exportPath: null, boundaryBinding: null },
531
+ inputs: [],
532
+ transitions: [],
533
+ gaps: [],
534
+ confidence: { source: "derived", level: "high" },
535
+ metadata: withGraphqlMetadata2(
536
+ withSourceDocumentMetadata(void 0, { label: source }),
537
+ { schemaSdl: sdl }
538
+ )
514
539
  };
515
540
  }
516
541
  function buildDeclaredContract(field, recognition) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-graphql",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "Generate behavioral summaries from GraphQL sources: a plain SDL file (root fields become resolver-kind summaries) or committed .graphql operation documents (each operation becomes a client-kind summary).",
6
6
  "keywords": [
@@ -45,7 +45,7 @@
45
45
  "typecheck": "tsc --noEmit"
46
46
  },
47
47
  "dependencies": {
48
- "@suss/behavioral-ir": "0.9.0",
48
+ "@suss/behavioral-ir": "0.11.0",
49
49
  "graphql": "^16.8.0"
50
50
  },
51
51
  "devDependencies": {