graphql-data-generator 0.4.7-alpha.0 → 0.4.7-alpha.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/esm/codegen.js CHANGED
@@ -77,7 +77,16 @@ const getType = ({ type, ...props }) => {
77
77
  // Use originalName for tracking field usage when field is aliased
78
78
  const fieldNameForTracking = originalName ?? name;
79
79
  if (def) {
80
- if (implementations.length) {
80
+ // Propagate to all implementations only when the selection comes
81
+ // from the outer type itself or from an interface that every
82
+ // implementation satisfies (e.g., a fragment on a shared
83
+ // interface). Selections from `... on ConcreteType` should be
84
+ // tracked only on that concrete type.
85
+ const shouldPropagate = implementations.length > 0 && (actualTypeName === type.name.value ||
86
+ (def[0].kind === "InterfaceTypeDefinition" &&
87
+ implementations.every((impl) => impl[0].kind === "ObjectTypeDefinition" &&
88
+ (impl[0].interfaces?.some((i) => i.name.value === actualTypeName) ?? false))));
89
+ if (shouldPropagate) {
81
90
  for (const implementation of implementations) {
82
91
  implementation[1].add(fieldNameForTracking);
83
92
  }
@@ -91,6 +100,13 @@ const getType = ({ type, ...props }) => {
91
100
  delete groupedValues[type.name.value];
92
101
  if (def?.[0].kind === "UnionTypeDefinition") {
93
102
  def[1].add(type.name.value);
103
+ // Ensure every union member gets emitted (even if no fields were
104
+ // selected on it), since the union declaration references it by name.
105
+ for (const memberType of def[0].types ?? []) {
106
+ const member = props.definitions[memberType.name.value];
107
+ if (member)
108
+ member[1].add(memberType.name.value);
109
+ }
94
110
  // This is a terrible solution and we should instead produce a tree that
95
111
  // is simplified
96
112
  let iface = props.definitions[def[0].types?.[0]?.name.value ?? ""]?.[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-data-generator",
3
- "version": "0.4.7-alpha.0",
3
+ "version": "0.4.7-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voces/graphql-data-generator.git"
package/script/codegen.js CHANGED
@@ -83,7 +83,16 @@ const getType = ({ type, ...props }) => {
83
83
  // Use originalName for tracking field usage when field is aliased
84
84
  const fieldNameForTracking = originalName ?? name;
85
85
  if (def) {
86
- if (implementations.length) {
86
+ // Propagate to all implementations only when the selection comes
87
+ // from the outer type itself or from an interface that every
88
+ // implementation satisfies (e.g., a fragment on a shared
89
+ // interface). Selections from `... on ConcreteType` should be
90
+ // tracked only on that concrete type.
91
+ const shouldPropagate = implementations.length > 0 && (actualTypeName === type.name.value ||
92
+ (def[0].kind === "InterfaceTypeDefinition" &&
93
+ implementations.every((impl) => impl[0].kind === "ObjectTypeDefinition" &&
94
+ (impl[0].interfaces?.some((i) => i.name.value === actualTypeName) ?? false))));
95
+ if (shouldPropagate) {
87
96
  for (const implementation of implementations) {
88
97
  implementation[1].add(fieldNameForTracking);
89
98
  }
@@ -97,6 +106,13 @@ const getType = ({ type, ...props }) => {
97
106
  delete groupedValues[type.name.value];
98
107
  if (def?.[0].kind === "UnionTypeDefinition") {
99
108
  def[1].add(type.name.value);
109
+ // Ensure every union member gets emitted (even if no fields were
110
+ // selected on it), since the union declaration references it by name.
111
+ for (const memberType of def[0].types ?? []) {
112
+ const member = props.definitions[memberType.name.value];
113
+ if (member)
114
+ member[1].add(memberType.name.value);
115
+ }
100
116
  // This is a terrible solution and we should instead produce a tree that
101
117
  // is simplified
102
118
  let iface = props.definitions[def[0].types?.[0]?.name.value ?? ""]?.[0];