graphql-codegen-compiler
Advanced tools
Comparing version 0.9.0-alpha.5fd20a9a to 0.9.0-alpha.6b9f20a7
@@ -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.5fd20a9a", | ||
"version": "0.9.0-alpha.6b9f20a7", | ||
"description": "GraphQL code generator compiler", | ||
@@ -28,5 +28,5 @@ "license": "MIT", | ||
"common-tags": "^1.4.0", | ||
"graphql-codegen-compiler": "^0.9.0-alpha.5fd20a9a", | ||
"graphql-codegen-core": "^0.9.0-alpha.5fd20a9a", | ||
"graphql-codegen-generators": "^0.9.0-alpha.5fd20a9a", | ||
"graphql-codegen-compiler": "0.9.0-alpha.6b9f20a7", | ||
"graphql-codegen-core": "0.9.0-alpha.6b9f20a7", | ||
"graphql-codegen-generators": "0.9.0-alpha.6b9f20a7", | ||
"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
+ Added@types/graphql@0.9.4(transitive)
+ Addedgraphql@0.10.5(transitive)
+ Addedgraphql-codegen-core@0.9.0-alpha.6b9f20a7(transitive)
+ Addedgraphql-codegen-generators@0.9.0-alpha.6b9f20a7(transitive)
+ Addedgraphql-tag@2.12.6(transitive)
+ Addedgraphql-tools@1.2.3(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@types/node@9.6.61(transitive)
- Removed@wry/equality@0.1.11(transitive)
- Removedapollo-link@1.2.1(transitive)
- Removedapollo-utilities@1.3.4(transitive)
- Removedasync@1.0.0(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedgraphql@0.13.2(transitive)
- Removedgraphql-codegen-core@0.9.4(transitive)
- Removedgraphql-codegen-generators@0.9.0-alpha.f365e6db(transitive)
- Removedgraphql-tag@2.9.2(transitive)
- Removedgraphql-tools@3.0.2(transitive)
- Removedisstream@0.1.2(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedts-invariant@0.4.4(transitive)
- Removedtslib@1.14.1(transitive)
- Removedwinston@2.4.3(transitive)
- Removedzen-observable@0.8.15(transitive)
- Removedzen-observable-ts@0.8.21(transitive)