graphql-codegen-compiler
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { Argument, Field } from 'graphql-codegen-core'; | ||
export declare function getFieldTypeAsString(field: Field | Argument): string; | ||
import { Argument, Field, Variable } from 'graphql-codegen-core'; | ||
export declare function getFieldTypeAsString(field: Field | Argument | Variable): string; |
@@ -54,19 +54,22 @@ "use strict"; | ||
if (!config.primitives[field.type]) { | ||
if (field.type === context.name) { | ||
return; | ||
} | ||
var fieldType = field_type_to_string_1.getFieldTypeAsString(field); | ||
var file = sanitizie_filename_1.sanitizeFilename(field.type, fieldType) + '.' + config.filesExtension; | ||
var file = sanitizie_filename_1.sanitizeFilename(field.type, fieldType); | ||
if (!imports.find(function (t) { return t.name === field.type; })) { | ||
imports.push({ name: field.type, file: file }); | ||
} | ||
// Fields arguments | ||
if (field.arguments && field.arguments.length > 0) { | ||
field.arguments.forEach(function (arg) { | ||
if (!config.primitives[arg.type]) { | ||
var fieldType_1 = field_type_to_string_1.getFieldTypeAsString(arg); | ||
var file_1 = sanitizie_filename_1.sanitizeFilename(arg.type, fieldType_1) + '.' + config.filesExtension; | ||
if (!imports.find(function (t) { return t.name === arg.type; })) { | ||
imports.push({ name: arg.type, file: file_1 }); | ||
} | ||
} | ||
// Fields arguments | ||
if (field.arguments && field.hasArguments) { | ||
field.arguments.forEach(function (arg) { | ||
if (!config.primitives[arg.type]) { | ||
var fieldType = field_type_to_string_1.getFieldTypeAsString(arg); | ||
var file = sanitizie_filename_1.sanitizeFilename(arg.type, fieldType); | ||
if (!imports.find(function (t) { return t.name === arg.type; })) { | ||
imports.push({ name: arg.type, file: file }); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -78,3 +81,3 @@ }); | ||
context.interfaces.forEach(function (infName) { | ||
var file = sanitizie_filename_1.sanitizeFilename(infName, 'interface') + '.' + config.filesExtension; | ||
var file = sanitizie_filename_1.sanitizeFilename(infName, 'interface'); | ||
if (!imports.find(function (t) { return t.name === infName; })) { | ||
@@ -88,3 +91,3 @@ imports.push({ name: infName, file: file }); | ||
context.possibleTypes.forEach(function (possibleType) { | ||
var file = sanitizie_filename_1.sanitizeFilename(possibleType, 'type') + '.' + config.filesExtension; | ||
var file = sanitizie_filename_1.sanitizeFilename(possibleType, 'type'); | ||
if (!imports.find(function (t) { return t.name === possibleType; })) { | ||
@@ -95,2 +98,13 @@ imports.push({ name: possibleType, file: file }); | ||
} | ||
if (context.variables) { | ||
context.variables.forEach(function (variable) { | ||
if (!config.primitives[variable.type]) { | ||
var fieldType = field_type_to_string_1.getFieldTypeAsString(variable); | ||
var file = sanitizie_filename_1.sanitizeFilename(variable.type, fieldType); | ||
if (!imports.find(function (t) { return t.name === variable.type; })) { | ||
imports.push({ name: variable.type, file: file }); | ||
} | ||
} | ||
}); | ||
} | ||
// Operations and Fragments | ||
@@ -102,3 +116,3 @@ if (context.selectionSet) { | ||
innerModel.fragmentsSpread.forEach(function (fragmentSpread) { | ||
var file = sanitizie_filename_1.sanitizeFilename(fragmentSpread.fragmentName, 'fragment') + '.' + config.filesExtension; | ||
var file = sanitizie_filename_1.sanitizeFilename(fragmentSpread.fragmentName, 'fragment'); | ||
if (!imports.find(function (t) { return t.name === fragmentSpread.fragmentName; })) { | ||
@@ -109,31 +123,30 @@ imports.push({ name: fragmentSpread.fragmentName, file: file }); | ||
} | ||
var schemaType = innerModel.schemaBaseType; | ||
var inputType = schemaContext.inputTypes.find(function (inputType) { return inputType.name === schemaType; }); | ||
if (inputType) { | ||
var file = sanitizie_filename_1.sanitizeFilename(inputType.name, 'input-type') + '.' + config.filesExtension; | ||
if (!imports.find(function (t) { return t.name === inputType.name; })) { | ||
imports.push({ name: inputType.name, file: file }); | ||
innerModel.fields.forEach(function (field) { | ||
if (!config.primitives[field.type]) { | ||
var type = null; | ||
if (field.isEnum) { | ||
type = 'enum'; | ||
} | ||
else if (field.isInputType) { | ||
type = 'input-type'; | ||
} | ||
else if (field.isScalar) { | ||
type = 'scalar'; | ||
} | ||
if (type !== null) { | ||
var file = sanitizie_filename_1.sanitizeFilename(field.type, type); | ||
if (!imports.find(function (t) { return t.name === field.type; })) { | ||
imports.push({ name: field.type, file: file }); | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
var enumType = schemaContext.enums.find(function (enumType) { return enumType.name === schemaType; }); | ||
if (enumType) { | ||
var file = sanitizie_filename_1.sanitizeFilename(enumType.name, 'enum') + '.' + config.filesExtension; | ||
if (!imports.find(function (t) { return t.name === enumType.name; })) { | ||
imports.push({ name: enumType.name, file: file }); | ||
} | ||
return; | ||
} | ||
var scalarType = schemaContext.scalars.find(function (scalarType) { return scalarType.name === schemaType; }); | ||
if (scalarType) { | ||
var file = sanitizie_filename_1.sanitizeFilename(scalarType.name, 'scalar') + '.' + config.filesExtension; | ||
if (!imports.find(function (t) { return t.name === scalarType.name; })) { | ||
imports.push({ name: scalarType.name, file: file }); | ||
} | ||
return; | ||
} | ||
}); | ||
}); | ||
} | ||
for (var i = 0, j = imports.length; i < j; i++) { | ||
ret = ret + options.fn(imports[i]); | ||
ret = ret + options.fn(imports[i], { | ||
data: { | ||
withExtension: imports[i] + '.' + config.filesExtension, | ||
}, | ||
}); | ||
} | ||
@@ -140,0 +153,0 @@ return ret; |
{ | ||
"name": "graphql-codegen-compiler", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "GraphQL code generator compiler", | ||
@@ -28,5 +28,5 @@ "license": "MIT", | ||
"common-tags": "^1.4.0", | ||
"graphql-codegen-compiler": "0.8.4", | ||
"graphql-codegen-core": "0.8.4", | ||
"graphql-codegen-generators": "0.8.4", | ||
"graphql-codegen-compiler": "0.8.5", | ||
"graphql-codegen-core": "0.8.5", | ||
"graphql-codegen-generators": "0.8.5", | ||
"handlebars": "^4.0.10" | ||
@@ -33,0 +33,0 @@ }, |
@@ -102,2 +102,13 @@ # `graphql-codegen-compiler` | ||
### `eachImport(element: any)` | ||
Iterates over a calculated array of imports (file names) that in use by the `element`. | ||
Example: | ||
```handlebars | ||
{{#eachImport type}} | ||
import { {{ name }} } from './{{file}}'; | ||
{{/eachImport}} | ||
``` | ||
## Other Template Helpers | ||
@@ -104,0 +115,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
143248
0.01%776
1.7%249
4.62%+ Added
+ Added
- Removed
- Removed
Updated