graphql-codegen-core
Advanced tools
Comparing version 0.6.0-alpha.7854fe32 to 0.6.0-alpha.836ffd2e
export { schemaToTemplateContext } from './schema/schema-to-template-context'; | ||
export { transformDocument } from './operations/transform-document'; | ||
export { validateIntrospection, introspectionToGraphQLSchema } from './utils/introspection-to-schema'; | ||
export { Argument, Field, Type, Scalar, Enum, EnumValue, Union, Interface, SchemaTemplateContext } from './types'; | ||
export { Argument, Field, Type, Scalar, Enum, EnumValue, Union, Interface, SchemaTemplateContext, Document, Variable, Operation, Fragment, SelectionSetItem, SelectionSetFieldNode, SelectionSetFragmentSpread, SelectionSetInlineFragment, isFieldNode, isFragmentSpreadNode, isInlineFragmentNode } from './types'; | ||
export { debugLog } from './debugging'; |
@@ -10,2 +10,8 @@ "use strict"; | ||
exports.introspectionToGraphQLSchema = introspection_to_schema_1.introspectionToGraphQLSchema; | ||
var types_1 = require("./types"); | ||
exports.isFieldNode = types_1.isFieldNode; | ||
exports.isFragmentSpreadNode = types_1.isFragmentSpreadNode; | ||
exports.isInlineFragmentNode = types_1.isInlineFragmentNode; | ||
var debugging_1 = require("./debugging"); | ||
exports.debugLog = debugging_1.debugLog; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var types_1 = require("../types"); | ||
var graphql_1 = require("graphql"); | ||
@@ -7,2 +16,16 @@ var kinds_1 = require("graphql/language/kinds"); | ||
var resolve_type_1 = require("../schema/resolve-type"); | ||
var debugging_1 = require("../debugging"); | ||
function separateSelectionSet(selectionSet) { | ||
var fields = selectionSet.filter(function (n) { return types_1.isFieldNode(n); }); | ||
var fragmentsSpread = selectionSet.filter(function (n) { return types_1.isFragmentSpreadNode(n); }); | ||
var inlineFragments = selectionSet.filter(function (n) { return types_1.isInlineFragmentNode(n); }); | ||
return { | ||
fragmentsSpread: fragmentsSpread, | ||
fields: fields, | ||
inlineFragments: inlineFragments, | ||
hasFragmentsSpread: fragmentsSpread.length > 0, | ||
hasFields: fields.length > 0, | ||
hasInlineFragments: inlineFragments.length > 0, | ||
}; | ||
} | ||
function buildSelectionSet(schema, rootObject, node) { | ||
@@ -12,15 +35,17 @@ return (node && node.selections ? node.selections : []).map(function (selectionNode) { | ||
var fieldNode = selectionNode; | ||
var name = fieldNode.alias && fieldNode.alias.value ? fieldNode.alias.value : fieldNode.name.value; | ||
debugging_1.debugLog("[buildSelectionSet] transforming FIELD with name " + name); | ||
var field = get_field_def_1.getFieldDef(rootObject, fieldNode); | ||
var resolvedType = resolve_type_1.resolveType(field.type); | ||
return { | ||
name: fieldNode.alias && fieldNode.alias.value ? fieldNode.alias.value : fieldNode.name.value, | ||
selectionSet: buildSelectionSet(schema, graphql_1.getNamedType(field.type), fieldNode.selectionSet), | ||
type: resolvedType.name, | ||
isRequired: resolvedType.isRequired, | ||
isArray: resolvedType.isArray, | ||
}; | ||
var childSelectionSet = buildSelectionSet(schema, graphql_1.getNamedType(field.type), fieldNode.selectionSet); | ||
return __assign({ isField: true, isFragmentSpread: false, isInlineFragment: false, isLeaf: childSelectionSet.length === 0, name: name, selectionSet: childSelectionSet }, separateSelectionSet(childSelectionSet), { type: resolvedType.name, isRequired: resolvedType.isRequired, isArray: resolvedType.isArray }); | ||
} | ||
else if (selectionNode.kind === kinds_1.FRAGMENT_SPREAD) { | ||
var fieldNode = selectionNode; | ||
debugging_1.debugLog("[buildSelectionSet] transforming FRAGMENT_SPREAD with name " + fieldNode.name.value + "..."); | ||
return { | ||
isField: false, | ||
isFragmentSpread: true, | ||
isInlineFragment: false, | ||
isLeaf: true, | ||
fragmentName: fieldNode.name.value, | ||
@@ -30,8 +55,7 @@ }; | ||
else if (selectionNode.kind === kinds_1.INLINE_FRAGMENT) { | ||
debugging_1.debugLog("[buildSelectionSet] transforming INLINE_FRAGMENT..."); | ||
var fieldNode = selectionNode; | ||
var nextRoot = graphql_1.typeFromAST(schema, fieldNode.typeCondition); | ||
return { | ||
selectionSet: buildSelectionSet(schema, nextRoot, fieldNode.selectionSet), | ||
onType: fieldNode.typeCondition.name.value, | ||
}; | ||
var childSelectionSet = buildSelectionSet(schema, nextRoot, fieldNode.selectionSet); | ||
return __assign({ isField: false, isFragmentSpread: false, isInlineFragment: true, isLeaf: childSelectionSet.length === 0, selectionSet: childSelectionSet }, separateSelectionSet(childSelectionSet), { onType: fieldNode.typeCondition.name.value }); | ||
} | ||
@@ -38,0 +62,0 @@ else { |
@@ -6,2 +6,3 @@ "use strict"; | ||
var transform_operation_1 = require("./transform-operation"); | ||
var debugging_1 = require("../debugging"); | ||
function transformDocument(schema, documentNode) { | ||
@@ -14,3 +15,5 @@ var result = { | ||
}; | ||
(documentNode.definitions || []).forEach(function (definitionNode) { | ||
var definitions = (documentNode.definitions || []); | ||
debugging_1.debugLog("[transformDocument] transforming total of " + definitions.length + " definitions..."); | ||
definitions.forEach(function (definitionNode) { | ||
if (definitionNode.kind === kinds_1.OPERATION_DEFINITION) { | ||
@@ -17,0 +20,0 @@ result.operations.push(transform_operation_1.transformOperation(schema, definitionNode)); |
@@ -5,3 +5,5 @@ "use strict"; | ||
var build_selection_set_1 = require("./build-selection-set"); | ||
var debugging_1 = require("../debugging"); | ||
function transformFragment(schema, fragment) { | ||
debugging_1.debugLog("[transformFragment] transforming fragment " + fragment.name.value + " on type " + fragment.typeCondition.name.value); | ||
var root = graphql_1.typeFromAST(schema, fragment.typeCondition); | ||
@@ -8,0 +10,0 @@ var name = fragment.name.value; |
@@ -6,7 +6,10 @@ "use strict"; | ||
var transform_variables_1 = require("./transform-variables"); | ||
var debugging_1 = require("../debugging"); | ||
function transformOperation(schema, operationNode) { | ||
var name = operationNode.name && operationNode.name.value ? operationNode.name.value : ''; | ||
debugging_1.debugLog("[transformOperation] transforming operation " + name + " of type " + operationNode.operation); | ||
var root = get_root_1.getRoot(schema, operationNode); | ||
var variables = transform_variables_1.transformVariables(schema, operationNode); | ||
return { | ||
name: operationNode.name && operationNode.name.value ? operationNode.name.value : '', | ||
name: name, | ||
selectionSet: build_selection_set_1.buildSelectionSet(schema, root, operationNode.selectionSet), | ||
@@ -13,0 +16,0 @@ operationType: operationNode.operation, |
@@ -5,2 +5,3 @@ "use strict"; | ||
var resolve_type_1 = require("../schema/resolve-type"); | ||
var debugging_1 = require("../debugging"); | ||
function transformVariables(schema, definitionNode) { | ||
@@ -10,2 +11,3 @@ return definitionNode.variableDefinitions.map(function (variableDefinition) { | ||
var resolvedType = resolve_type_1.resolveType(typeFromSchema); | ||
debugging_1.debugLog("[transformVariables] transforming variable " + variableDefinition.variable.name.value + " of type " + resolvedType.name); | ||
return { | ||
@@ -12,0 +14,0 @@ name: variableDefinition.variable.name.value, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var resolve_type_1 = require("./resolve-type"); | ||
var resolve_type_indicators_1 = require("./resolve-type-indicators"); | ||
var debugging_1 = require("../debugging"); | ||
function resolveArguments(args) { | ||
return args.map(function (arg) { | ||
var type = resolve_type_1.resolveType(arg.type); | ||
var namedType = graphql_1.getNamedType(arg.type); | ||
var indicators = resolve_type_indicators_1.resolveTypeIndicators(namedType); | ||
debugging_1.debugLog("[resolveArguments] resolving argument " + arg.name + " of type " + type.name + "..."); | ||
return { | ||
@@ -13,2 +19,8 @@ name: arg.name, | ||
isArray: type.isArray, | ||
isEnum: indicators.isEnum, | ||
isScalar: indicators.isScalar, | ||
isInterface: indicators.isInterface, | ||
isUnion: indicators.isUnion, | ||
isInputType: indicators.isInputType, | ||
isType: indicators.isType, | ||
}; | ||
@@ -15,0 +27,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var debugging_1 = require("../debugging"); | ||
function isRequired(type) { | ||
@@ -13,4 +14,6 @@ return (String(type)).indexOf('!') > -1; | ||
function resolveType(type) { | ||
var name = graphql_1.getNamedType(type).name; | ||
debugging_1.debugLog("[resolveType] resolving type " + name); | ||
return { | ||
name: graphql_1.getNamedType(type).name, | ||
name: name, | ||
isRequired: isRequired(type), | ||
@@ -17,0 +20,0 @@ isArray: isArray(type), |
@@ -10,2 +10,3 @@ "use strict"; | ||
var transform_scalar_1 = require("./transform-scalar"); | ||
var debugging_1 = require("../debugging"); | ||
var GRAPHQL_PRIMITIVES = ['String', 'Int', 'Boolean', 'ID', 'Float']; | ||
@@ -19,2 +20,3 @@ var clearTypes = function (typesMap) { return Object.keys(typesMap) | ||
function schemaToTemplateContext(schema) { | ||
debugging_1.debugLog('[schemaToTemplateContext] started...'); | ||
var result = { | ||
@@ -37,2 +39,3 @@ types: [], | ||
var typesArray = object_map_to_array_1.objectMapToArray(typesMap); | ||
debugging_1.debugLog("[schemaToTemplateContext] Got total of " + typesArray.length + " types in the GraphQL schema"); | ||
typesArray.map(function (graphQlType) { | ||
@@ -68,2 +71,3 @@ var actualTypeDef = graphQlType.value; | ||
result.hasInterfaces = result.interfaces.length > 0; | ||
debugging_1.debugLog("[schemaToTemplateContext] done, results is: ", result); | ||
return result; | ||
@@ -70,0 +74,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var debugging_1 = require("../debugging"); | ||
function transformGraphQLEnum(graphqlEnum) { | ||
debugging_1.debugLog("[transformGraphQLEnum] transformed enum " + graphqlEnum.name); | ||
var enumValues = graphqlEnum.getValues().map(function (enumItem) { | ||
@@ -5,0 +7,0 @@ return { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var object_map_to_array_1 = require("../utils/object-map-to-array"); | ||
var resolve_type_1 = require("./resolve-type"); | ||
var resolve_arguments_1 = require("./resolve-arguments"); | ||
var resolve_type_indicators_1 = require("./resolve-type-indicators"); | ||
var debugging_1 = require("../debugging"); | ||
function resolveFields(rawFields) { | ||
@@ -11,2 +14,5 @@ var fieldsArray = object_map_to_array_1.objectMapToArray(rawFields); | ||
var resolvedArguments = resolve_arguments_1.resolveArguments(item.value.args || []); | ||
var namedType = graphql_1.getNamedType(item.value.type); | ||
var indicators = resolve_type_indicators_1.resolveTypeIndicators(namedType); | ||
debugging_1.debugLog("[resolveFields] transformed field " + item.value.name + " of type " + type + ", resolved type is: ", type); | ||
return { | ||
@@ -20,2 +26,8 @@ name: item.value.name, | ||
hasArguments: resolvedArguments.length > 0, | ||
isEnum: indicators.isEnum, | ||
isScalar: indicators.isScalar, | ||
isInterface: indicators.isInterface, | ||
isUnion: indicators.isUnion, | ||
isInputType: indicators.isInputType, | ||
isType: indicators.isType, | ||
}; | ||
@@ -22,0 +34,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var transform_fields_1 = require("./transform-fields"); | ||
var debugging_1 = require("../debugging"); | ||
function transformInterface(gqlInterface) { | ||
debugging_1.debugLog("[transformInterface] transformed interface " + gqlInterface.name); | ||
var resolvedFields = transform_fields_1.resolveFields(gqlInterface.getFields()); | ||
@@ -6,0 +8,0 @@ return { |
@@ -5,3 +5,5 @@ "use strict"; | ||
var transform_fields_1 = require("./transform-fields"); | ||
var debugging_1 = require("../debugging"); | ||
function transformGraphQLObject(object) { | ||
debugging_1.debugLog("[transformGraphQLObject] transforming type " + object.name); | ||
var resolvedFields = transform_fields_1.resolveFields(object.getFields()); | ||
@@ -8,0 +10,0 @@ var resolvedInterfaces = object instanceof graphql_1.GraphQLObjectType ? object.getInterfaces().map(function (inf) { return inf.name; }) : []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var debugging_1 = require("../debugging"); | ||
function transformScalar(scalar) { | ||
debugging_1.debugLog("[transformInterface] transformed custom scalar " + scalar.name); | ||
return { | ||
@@ -5,0 +7,0 @@ name: scalar.name, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var debugging_1 = require("../debugging"); | ||
function transformUnion(union) { | ||
debugging_1.debugLog("[transformUnion] transformed union " + union.name); | ||
return { | ||
@@ -5,0 +7,0 @@ name: union.name, |
@@ -7,2 +7,8 @@ export interface Argument { | ||
isArray: boolean; | ||
isType: boolean; | ||
isScalar: boolean; | ||
isInterface: boolean; | ||
isUnion: boolean; | ||
isInputType: boolean; | ||
isEnum: boolean; | ||
} | ||
@@ -17,2 +23,8 @@ export interface Field { | ||
hasArguments: boolean; | ||
isType: boolean; | ||
isScalar: boolean; | ||
isInterface: boolean; | ||
isUnion: boolean; | ||
isInputType: boolean; | ||
isEnum: boolean; | ||
} | ||
@@ -68,2 +80,6 @@ export interface Type { | ||
export interface SelectionSetItem { | ||
isFragmentSpread: boolean; | ||
isInlineFragment: boolean; | ||
isField: boolean; | ||
isLeaf: boolean; | ||
} | ||
@@ -73,2 +89,8 @@ export interface SelectionSetInlineFragment extends SelectionSetItem { | ||
onType: string; | ||
fields: SelectionSetFieldNode[]; | ||
fragmentsSpread: SelectionSetFragmentSpread[]; | ||
inlineFragments: SelectionSetInlineFragment[]; | ||
hasFragmentsSpread: boolean; | ||
hasInlineFragments: boolean; | ||
hasFields: boolean; | ||
} | ||
@@ -79,8 +101,17 @@ export interface SelectionSetFragmentSpread extends SelectionSetItem { | ||
export interface SelectionSetFieldNode extends SelectionSetItem { | ||
selectionSet: SelectionSetItem[]; | ||
name: string; | ||
selectionSet: SelectionSetItem[]; | ||
type: string; | ||
isRequired: boolean; | ||
isArray: boolean; | ||
fields: SelectionSetFieldNode[]; | ||
fragmentsSpread: SelectionSetFragmentSpread[]; | ||
inlineFragments: SelectionSetInlineFragment[]; | ||
hasFragmentsSpread: boolean; | ||
hasInlineFragments: boolean; | ||
hasFields: boolean; | ||
} | ||
export declare function isFieldNode(node: SelectionSetItem): node is SelectionSetFieldNode; | ||
export declare function isFragmentSpreadNode(node: SelectionSetItem): node is SelectionSetFragmentSpread; | ||
export declare function isInlineFragmentNode(node: SelectionSetItem): node is SelectionSetInlineFragment; | ||
export interface Fragment { | ||
@@ -87,0 +118,0 @@ name: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isFieldNode(node) { | ||
return node['name'] !== undefined && node['selectionSet'] !== undefined && node['type'] !== undefined; | ||
} | ||
exports.isFieldNode = isFieldNode; | ||
function isFragmentSpreadNode(node) { | ||
return node['fragmentName'] !== undefined; | ||
} | ||
exports.isFragmentSpreadNode = isFragmentSpreadNode; | ||
function isInlineFragmentNode(node) { | ||
return node['selectionSet'] !== undefined && node['onType'] !== undefined; | ||
} | ||
exports.isInlineFragmentNode = isInlineFragmentNode; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "graphql-codegen-core", | ||
"version": "0.6.0-alpha.7854fe32", | ||
"version": "0.6.0-alpha.836ffd2e", | ||
"description": "GraphQL types and code generator based on schema", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build-tests": "tsc -p tsconfig.test.json", | ||
"watch": "tsc --watch", | ||
"clean": "rimraf ./dist", | ||
@@ -16,6 +14,2 @@ "lint": "tslint src/**/*.ts", | ||
"debug": "cd dist && node --inspect --debug-brk gql-gen.js", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"create-git-tag": "git tag $(cat package.json | json version)", | ||
"dev": "cd dist/cli && nodemon --ext ts,js,d.ts,template,graphql,json,handlebars gql-gen.js --dev --file ../../dev-test/githunt/schema.json --template ts --out ../../dev-test/githunt/typings.d.ts ../../dev-test/githunt/**/*.graphql", | ||
"prepare--": "npm run build && npm run test && npm run create-git-tag && git push && git push --tags", | ||
"test": "jest --no-cache --verbose --runInBand" | ||
@@ -22,0 +16,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
239814
72
784