graphql-codegen-core
Advanced tools
Comparing version 0.6.0-alpha.7854fe32 to 0.6.0-alpha.8640f1df
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'; |
@@ -10,2 +10,6 @@ "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; | ||
//# 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,15 @@ var kinds_1 = require("graphql/language/kinds"); | ||
var resolve_type_1 = require("../schema/resolve-type"); | ||
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) { | ||
@@ -14,9 +36,4 @@ return (node && node.selections ? node.selections : []).map(function (selectionNode) { | ||
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: fieldNode.alias && fieldNode.alias.value ? fieldNode.alias.value : fieldNode.name.value, selectionSet: childSelectionSet }, separateSelectionSet(childSelectionSet), { type: resolvedType.name, isRequired: resolvedType.isRequired, isArray: resolvedType.isArray }); | ||
} | ||
@@ -26,2 +43,6 @@ else if (selectionNode.kind === kinds_1.FRAGMENT_SPREAD) { | ||
return { | ||
isField: false, | ||
isFragmentSpread: true, | ||
isInlineFragment: false, | ||
isLeaf: true, | ||
fragmentName: fieldNode.name.value, | ||
@@ -33,6 +54,4 @@ }; | ||
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 }); | ||
} | ||
@@ -39,0 +58,0 @@ else { |
"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"); | ||
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); | ||
return { | ||
@@ -13,2 +17,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 +25,0 @@ }); |
"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"); | ||
function resolveFields(rawFields) { | ||
@@ -11,2 +13,4 @@ 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); | ||
return { | ||
@@ -20,2 +24,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 +32,0 @@ }); |
@@ -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.8640f1df", | ||
"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
235019
69
732