graphql-codegen-core
Advanced tools
Comparing version 0.19.0-alpha.2249ff45 to 0.19.0-alpha.22df701b
import { GraphQLSchema } from 'graphql'; | ||
import { SchemaTemplateContext } from '../types'; | ||
export declare function schemaToTemplateContext(schema: GraphQLSchema): SchemaTemplateContext; | ||
import { SchemaTemplateContext, DocumentFile } from '../types'; | ||
export declare function schemaToTemplateContext(schema: GraphQLSchema, documents?: DocumentFile[]): SchemaTemplateContext; |
@@ -14,5 +14,5 @@ "use strict"; | ||
var GRAPHQL_PRIMITIVES = ['String', 'Int', 'Boolean', 'ID', 'Float']; | ||
var clearTypes = function (typesMap) { | ||
var clearTypes = function (typesMap, forcedTypes) { | ||
return Object.keys(typesMap) | ||
.filter(function (key) { return !GRAPHQL_PRIMITIVES.includes(key) && !key.startsWith('__'); }) | ||
.filter(function (key) { return forcedTypes.includes(key) || (!GRAPHQL_PRIMITIVES.includes(key) && !key.startsWith('__')); }) | ||
.reduce(function (obj, key) { | ||
@@ -23,4 +23,5 @@ obj[key] = typesMap[key]; | ||
}; | ||
function schemaToTemplateContext(schema) { | ||
function schemaToTemplateContext(schema, documents) { | ||
debugging_1.debugLog('[schemaToTemplateContext] started...'); | ||
var introspectionTypesToInclude = includeIntrospectionTypes(schema, documents); | ||
var directives = graphql_toolkit_1.getDirectives(schema, schema); | ||
@@ -48,3 +49,3 @@ var result = { | ||
var rawTypesMap = schema.getTypeMap(); | ||
var typesMap = clearTypes(rawTypesMap); | ||
var typesMap = clearTypes(rawTypesMap, introspectionTypesToInclude.map(function (t) { return t.name; })); | ||
var typesArray = object_map_to_array_1.objectMapToArray(typesMap); | ||
@@ -89,2 +90,18 @@ debugging_1.debugLog("[schemaToTemplateContext] Got total of " + typesArray.length + " types in the GraphQL schema"); | ||
exports.schemaToTemplateContext = schemaToTemplateContext; | ||
function includeIntrospectionTypes(schema, documents) { | ||
var typesToInclude = []; | ||
if (documents) { | ||
var typeInfo_1 = new graphql_1.TypeInfo(schema); | ||
var visitor_1 = graphql_1.visitWithTypeInfo(typeInfo_1, { | ||
Field: function () { | ||
var type = graphql_1.getNamedType(typeInfo_1.getType()); | ||
if (graphql_1.isIntrospectionType(type) && graphql_1.isEnumType(type) && !typesToInclude.includes(type)) { | ||
typesToInclude.push(type); | ||
} | ||
} | ||
}); | ||
documents.forEach(function (doc) { return graphql_1.visit(doc.content, visitor_1); }); | ||
} | ||
return typesToInclude; | ||
} | ||
//# sourceMappingURL=schema-to-template-context.js.map |
{ | ||
"name": "graphql-codegen-core", | ||
"version": "0.19.0-alpha.2249ff45", | ||
"version": "0.19.0-alpha.22df701b", | ||
"description": "GraphQL types and code generator based on schema", | ||
@@ -18,3 +18,3 @@ "main": "dist/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/dotansimha/graphql-codegen.git" | ||
"url": "git+https://github.com/dotansimha/graphql-code-generator.git" | ||
}, | ||
@@ -68,3 +68,3 @@ "keywords": [ | ||
"graphql-tag": "2.10.1", | ||
"graphql-toolkit": "0.2.0", | ||
"graphql-toolkit": "0.2.5", | ||
"graphql-tools": "4.0.4", | ||
@@ -71,0 +71,0 @@ "ts-log": "2.1.4", |
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
93340
1358
+ Addedaggregate-error@2.2.0(transitive)
+ Addedgraphql-tag-pluck@0.7.0(transitive)
+ Addedgraphql-toolkit@0.2.5(transitive)
- Removedaggregate-error@2.1.0(transitive)
- Removedgraphql-tag-pluck@0.6.0(transitive)
- Removedgraphql-toolkit@0.2.0(transitive)
Updatedgraphql-toolkit@0.2.5