@vladimirdev635/gql-codegen 0.0.90 → 0.0.92

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/schema/utils.js CHANGED
@@ -79,7 +79,7 @@ export function buildFragmentFromUnion(union) {
79
79
  };
80
80
  }
81
81
  ;
82
- function extractFieldFromNonCallableFieldSpec(spec) {
82
+ function extractFieldFromObjectLiteralFieldSpec(spec) {
83
83
  switch (spec.type._type) {
84
84
  case 'Enum': return '';
85
85
  case 'Scalar': return '';
@@ -91,19 +91,23 @@ function extractFieldFromNonCallableFieldSpec(spec) {
91
91
  ;
92
92
  }
93
93
  ;
94
- function buildInputField(field) {
95
- let str = '';
96
- if (field.spec._type === 'array') {
97
- str += '[';
94
+ function extractFieldFromNonCallableFieldSpec(spec) {
95
+ switch (spec._type) {
96
+ case 'literal': return extractFieldFromObjectLiteralFieldSpec(spec);
97
+ case 'array': return extractFieldFromNonCallableFieldSpec(spec.type);
98
98
  }
99
- ;
100
- str += field.spec.type.name;
101
- if (field.spec._type === 'array') {
102
- if (!field.spec.nullable)
103
- str += '!';
104
- str += ']';
99
+ }
100
+ ;
101
+ function buildInputFieldSpec(spec) {
102
+ switch (spec._type) {
103
+ case 'literal': return spec.type._type;
104
+ case 'array':
105
+ return '[' + buildInputFieldSpec(spec.type) +
106
+ spec.nullable ? '' : '!' + ']';
105
107
  }
106
- ;
108
+ }
109
+ function buildInputField(field) {
110
+ let str = buildInputFieldSpec(field.spec);
107
111
  if (!field.nullable) {
108
112
  str += '!';
109
113
  }
@@ -153,24 +157,28 @@ function generateUnionFragmentSpecText(union) {
153
157
  }
154
158
  export function buildSelectionFromFieldSpec(spec) {
155
159
  const type = extractTypeFromObjectFieldSpec(spec);
156
- if (type._type === 'Enum' || type._type === 'Scalar')
157
- return null;
158
- switch (type._type) {
160
+ if (type._type === 'array')
161
+ return buildSelectionFromFieldSpec(type.type);
162
+ if (type._type !== 'literal')
163
+ throw new Error('Unexpected condition');
164
+ switch (type.type._type) {
165
+ case 'Enum':
166
+ case 'Scalar': return null;
159
167
  case 'ObjectType':
160
168
  case 'InterfaceType':
161
169
  return {
162
170
  _type: 'ObjectFragmentSpec',
163
- name: type.name,
171
+ name: type.type.name,
164
172
  selections: [
165
- { _type: 'SpreadSelection', fragment: type.name }
173
+ { _type: 'SpreadSelection', fragment: type.type.name }
166
174
  ]
167
175
  };
168
176
  case 'Union':
169
177
  return {
170
178
  _type: 'UnionFragmentSpec',
171
- name: type.name,
179
+ name: type.type.name,
172
180
  selections: [
173
- { _type: 'SpreadSelection', fragment: type.name }
181
+ { _type: 'SpreadSelection', fragment: type.type.name }
174
182
  ]
175
183
  };
176
184
  }