@graphql-tools/utils
Advanced tools
Comparing version 5.0.1-alpha-719b0ec.0 to 5.0.1-alpha-7ecf9b1.0
@@ -147,73 +147,2 @@ 'use strict'; | ||
function extractFieldResolversFromObjectType(objectType, options) { | ||
const fieldResolvers = {}; | ||
const fieldMap = objectType.getFields(); | ||
let selectedFieldNames; | ||
if (options && options.selectedTypeDefs) { | ||
const invalidSchema = graphql.buildASTSchema(options.selectedTypeDefs); | ||
const typeMap = invalidSchema.getTypeMap(); | ||
if (!(objectType.name in typeMap)) { | ||
return {}; | ||
} | ||
const selectedObjectType = typeMap[objectType.name]; | ||
selectedFieldNames = Object.keys(selectedObjectType.getFields()); | ||
} | ||
for (const fieldName in fieldMap) { | ||
if (selectedFieldNames && !selectedFieldNames.includes(fieldName)) { | ||
continue; | ||
} | ||
const fieldDefinition = fieldMap[fieldName]; | ||
fieldResolvers[fieldName] = { | ||
subscribe: fieldDefinition.subscribe, | ||
resolve: fieldDefinition.resolve, | ||
}; | ||
} | ||
if ('resolveType' in objectType) { | ||
fieldResolvers.__resolveType = objectType.resolveType; | ||
} | ||
if ('isTypeOf' in objectType) { | ||
fieldResolvers.__isTypeOf = objectType.isTypeOf; | ||
} | ||
return fieldResolvers; | ||
} | ||
function extractResolversFromSchema(schema, options) { | ||
let selectedTypeNames; | ||
const resolvers = {}; | ||
const typeMap = schema.getTypeMap(); | ||
if (options && options.selectedTypeDefs) { | ||
const invalidSchema = graphql.buildASTSchema(options.selectedTypeDefs); | ||
selectedTypeNames = Object.keys(invalidSchema.getTypeMap()); | ||
} | ||
for (const typeName in typeMap) { | ||
if (!typeName.startsWith('__')) { | ||
const typeDef = typeMap[typeName]; | ||
if (selectedTypeNames && !selectedTypeNames.includes(typeName)) { | ||
continue; | ||
} | ||
if (graphql.isScalarType(typeDef)) { | ||
resolvers[typeName] = typeDef; | ||
} | ||
else if (graphql.isObjectType(typeDef) || graphql.isInterfaceType(typeDef)) { | ||
resolvers[typeName] = extractFieldResolversFromObjectType(typeDef, { | ||
selectedTypeDefs: options && options.selectedTypeDefs, | ||
}); | ||
} | ||
else if (graphql.isEnumType(typeDef)) { | ||
const enumValues = typeDef.getValues(); | ||
resolvers[typeName] = {}; | ||
for (const { name, value } of enumValues) { | ||
resolvers[typeName][name] = value; | ||
} | ||
} | ||
else if (graphql.isUnionType(typeDef)) { | ||
resolvers[typeName] = { | ||
__resolveType: typeDef.resolveType, | ||
}; | ||
} | ||
} | ||
} | ||
return resolvers; | ||
} | ||
const fixWindowsPath = (path) => path.replace(/\\/g, '/'); | ||
@@ -1000,4 +929,2 @@ | ||
exports.debugLog = debugLog; | ||
exports.extractFieldResolversFromObjectType = extractFieldResolversFromObjectType; | ||
exports.extractResolversFromSchema = extractResolversFromSchema; | ||
exports.fixSchemaAst = fixSchemaAst; | ||
@@ -1004,0 +931,0 @@ exports.fixWindowsPath = fixWindowsPath; |
export * from './loaders'; | ||
export * from './helpers'; | ||
export * from './debug-log'; | ||
export * from './extract-field-resolvers-from-object-type'; | ||
export * from './extract-resolvers-from-schema'; | ||
export * from './fix-windows-path'; | ||
@@ -7,0 +5,0 @@ export * from './flatten-array'; |
@@ -1,2 +0,2 @@ | ||
import { parse, buildASTSchema, isScalarType, isObjectType, isInterfaceType, isEnumType, isUnionType, getDirectiveValues, Kind, isSpecifiedScalarType, isIntrospectionType, print, printType, specifiedRules, validate, buildSchema, buildClientSchema, Source, isListType, isNonNullType, getNamedType } from 'graphql'; | ||
import { parse, getDirectiveValues, Kind, isObjectType, isScalarType, isSpecifiedScalarType, isIntrospectionType, print, printType, specifiedRules, validate, buildSchema, buildClientSchema, Source, isListType, isNonNullType, getNamedType, isUnionType, isInterfaceType } from 'graphql'; | ||
import AggregateError from 'aggregate-error'; | ||
@@ -122,73 +122,2 @@ import { get, set } from 'lodash'; | ||
function extractFieldResolversFromObjectType(objectType, options) { | ||
const fieldResolvers = {}; | ||
const fieldMap = objectType.getFields(); | ||
let selectedFieldNames; | ||
if (options && options.selectedTypeDefs) { | ||
const invalidSchema = buildASTSchema(options.selectedTypeDefs); | ||
const typeMap = invalidSchema.getTypeMap(); | ||
if (!(objectType.name in typeMap)) { | ||
return {}; | ||
} | ||
const selectedObjectType = typeMap[objectType.name]; | ||
selectedFieldNames = Object.keys(selectedObjectType.getFields()); | ||
} | ||
for (const fieldName in fieldMap) { | ||
if (selectedFieldNames && !selectedFieldNames.includes(fieldName)) { | ||
continue; | ||
} | ||
const fieldDefinition = fieldMap[fieldName]; | ||
fieldResolvers[fieldName] = { | ||
subscribe: fieldDefinition.subscribe, | ||
resolve: fieldDefinition.resolve, | ||
}; | ||
} | ||
if ('resolveType' in objectType) { | ||
fieldResolvers.__resolveType = objectType.resolveType; | ||
} | ||
if ('isTypeOf' in objectType) { | ||
fieldResolvers.__isTypeOf = objectType.isTypeOf; | ||
} | ||
return fieldResolvers; | ||
} | ||
function extractResolversFromSchema(schema, options) { | ||
let selectedTypeNames; | ||
const resolvers = {}; | ||
const typeMap = schema.getTypeMap(); | ||
if (options && options.selectedTypeDefs) { | ||
const invalidSchema = buildASTSchema(options.selectedTypeDefs); | ||
selectedTypeNames = Object.keys(invalidSchema.getTypeMap()); | ||
} | ||
for (const typeName in typeMap) { | ||
if (!typeName.startsWith('__')) { | ||
const typeDef = typeMap[typeName]; | ||
if (selectedTypeNames && !selectedTypeNames.includes(typeName)) { | ||
continue; | ||
} | ||
if (isScalarType(typeDef)) { | ||
resolvers[typeName] = typeDef; | ||
} | ||
else if (isObjectType(typeDef) || isInterfaceType(typeDef)) { | ||
resolvers[typeName] = extractFieldResolversFromObjectType(typeDef, { | ||
selectedTypeDefs: options && options.selectedTypeDefs, | ||
}); | ||
} | ||
else if (isEnumType(typeDef)) { | ||
const enumValues = typeDef.getValues(); | ||
resolvers[typeName] = {}; | ||
for (const { name, value } of enumValues) { | ||
resolvers[typeName][name] = value; | ||
} | ||
} | ||
else if (isUnionType(typeDef)) { | ||
resolvers[typeName] = { | ||
__resolveType: typeDef.resolveType, | ||
}; | ||
} | ||
} | ||
} | ||
return resolvers; | ||
} | ||
const fixWindowsPath = (path) => path.replace(/\\/g, '/'); | ||
@@ -966,3 +895,3 @@ | ||
export { asArray, buildOperationNodeForField, chainFunctions, checkValidationErrors, compareNodes, compareStrings, composeResolvers, createSchemaDefinition, debugLog, extractFieldResolversFromObjectType, extractResolversFromSchema, fixSchemaAst, fixWindowsPath, flattenArray, getDirectives, getFieldsWithDirectives, getImplementingTypes, getUserTypesFromSchema, isDocumentString, isEqual, isNotEqual, isValidPath, nodeToString, parseGraphQLJSON, parseGraphQLSDL, printSchemaWithDirectives, resolveBuiltinModule, resolveBuiltinModuleSync, validateGraphQlDocuments }; | ||
export { asArray, buildOperationNodeForField, chainFunctions, checkValidationErrors, compareNodes, compareStrings, composeResolvers, createSchemaDefinition, debugLog, fixSchemaAst, fixWindowsPath, flattenArray, getDirectives, getFieldsWithDirectives, getImplementingTypes, getUserTypesFromSchema, isDocumentString, isEqual, isNotEqual, isValidPath, nodeToString, parseGraphQLJSON, parseGraphQLSDL, printSchemaWithDirectives, resolveBuiltinModule, resolveBuiltinModuleSync, validateGraphQlDocuments }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@graphql-tools/utils", | ||
"version": "5.0.1-alpha-719b0ec.0", | ||
"version": "5.0.1-alpha-7ecf9b1.0", | ||
"description": "Common package containting utils and types for GraphQL tools", | ||
"peerDependencies": { | ||
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0" | ||
"graphql": "^14.0.0 || ^15.0.0" | ||
}, | ||
@@ -11,3 +11,2 @@ "dependencies": { | ||
"camel-case": "4.1.1", | ||
"@graphql-tools/schema-stitching": "5.0.1-alpha-719b0ec.0", | ||
"lodash": "4.17.15" | ||
@@ -14,0 +13,0 @@ }, |
@@ -1,6 +0,6 @@ | ||
import { IResolvers, IFieldResolver } from '@graphql-tools/schema-stitching'; | ||
export declare type ResolversComposition<Resolver extends IFieldResolver<any, any> = IFieldResolver<any, any>> = (next: Resolver) => Resolver; | ||
export declare type ResolversComposerMapping<Resolvers extends IResolvers = IResolvers> = { | ||
import { GraphQLFieldResolver } from 'graphql'; | ||
export declare type ResolversComposition<Resolver extends GraphQLFieldResolver<any, any> = GraphQLFieldResolver<any, any>> = (next: Resolver) => Resolver; | ||
export declare type ResolversComposerMapping<Resolvers extends Record<string, any> = Record<string, any>> = { | ||
[TypeName in keyof Resolvers]?: { | ||
[FieldName in keyof Resolvers[TypeName]]: Resolvers[TypeName][FieldName] extends IFieldResolver<any, any> ? ResolversComposition<Resolvers[TypeName][FieldName]> | Array<ResolversComposition<Resolvers[TypeName][FieldName]>> : ResolversComposition | ResolversComposition[]; | ||
[FieldName in keyof Resolvers[TypeName]]: Resolvers[TypeName][FieldName] extends GraphQLFieldResolver<any, any> ? ResolversComposition<Resolvers[TypeName][FieldName]> | Array<ResolversComposition<Resolvers[TypeName][FieldName]>> : ResolversComposition | ResolversComposition[]; | ||
}; | ||
@@ -18,2 +18,2 @@ } | { | ||
*/ | ||
export declare function composeResolvers<Resolvers extends IResolvers>(resolvers: Resolvers, mapping?: ResolversComposerMapping<Resolvers>): Resolvers; | ||
export declare function composeResolvers<Resolvers extends Record<string, any>>(resolvers: Resolvers, mapping?: ResolversComposerMapping<Resolvers>): Resolvers; |
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
4
202857
24
1981
+ Addedtslib@1.14.1(transitive)
- Removed@graphql-tools/schema-stitching@5.0.1-alpha-719b0ec.0
- Removed@babel/runtime@7.26.0(transitive)
- Removed@graphql-tools/schema-stitching@5.0.1-alpha-719b0ec.0(transitive)
- Removed@wry/equality@0.1.11(transitive)
- Removedapollo-link@1.2.14(transitive)
- Removedapollo-link-http-common@0.2.16(transitive)
- Removedapollo-upload-client@13.0.0(transitive)
- Removedapollo-utilities@1.3.4(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcross-fetch@3.0.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedextract-files@8.1.0(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedform-data@3.0.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednode-fetch@2.6.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedts-invariant@0.4.4(transitive)
- Removedtslib@1.11.1(transitive)
- Removedwhatwg-fetch@3.0.0(transitive)
- Removedzen-observable@0.8.15(transitive)
- Removedzen-observable-ts@0.8.21(transitive)