graphql-codegen-compiler
Advanced tools
Comparing version 0.9.0-alpha.1a4d72cb to 0.9.0-alpha.2f7495c1
@@ -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; |
@@ -51,22 +51,25 @@ "use strict"; | ||
// Interface, input types, types | ||
if (context.fields) { | ||
if (context.fields && !context.onType && !context.operationType) { | ||
context.fields.forEach(function (field) { | ||
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.9.0-alpha.1a4d72cb", | ||
"version": "0.9.0-alpha.2f7495c1", | ||
"description": "GraphQL code generator compiler", | ||
@@ -28,5 +28,5 @@ "license": "MIT", | ||
"common-tags": "^1.4.0", | ||
"graphql-codegen-compiler": "0.9.0-alpha.1a4d72cb", | ||
"graphql-codegen-core": "0.9.0-alpha.1a4d72cb", | ||
"graphql-codegen-generators": "0.9.0-alpha.1a4d72cb", | ||
"graphql-codegen-compiler": "0.9.0-alpha.2f7495c1", | ||
"graphql-codegen-core": "0.9.0-alpha.2f7495c1", | ||
"graphql-codegen-generators": "0.9.0-alpha.2f7495c1", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143308
776
249
+ Addedgraphql-codegen-core@0.9.0-alpha.2f7495c1(transitive)
+ Addedgraphql-codegen-generators@0.9.0-alpha.2f7495c1(transitive)
- Removedgraphql-codegen-core@0.9.0-alpha.1a4d72cb(transitive)
- Removedgraphql-codegen-generators@0.9.0-alpha.1a4d72cb(transitive)