@beamf/graphql-schema-typescript
Advanced tools
Comparing version 1.2.5 to 1.3.0
@@ -60,3 +60,13 @@ "use strict"; | ||
// 'export type Value<T> = T | Promise<T>', | ||
'' | ||
'', | ||
'/**', | ||
' * Technically a property can be a function also. We DO NOT support this use case', | ||
' * because it does not feel like a good coding pattern to put resolver-like functions', | ||
' * on to of the object itself. If needed, property with getter can be used', | ||
' * which takes the property of the source object of the same name as the field', | ||
" * and returns it as the Value, or if it's a function, returns the Value", | ||
' * of calling that function while passing along args, context and info.', | ||
' * NOTE how the function signature does not have parent', | ||
' */', | ||
'export type GQLProperty<T, Args, Ctx> = T | Promise<T> | ((args: Args, context: Ctx, info: GraphQLResolveInfo) => T | Promise<T>)', | ||
]; | ||
@@ -249,8 +259,11 @@ return [2 /*return*/, gqlTypes.reduce(function (prevTypescriptDefs, gqlType) { | ||
var uppercaseFisrtFieldName = utils_1.toUppercaseFirst(field.name); | ||
// If there is argument, require an explicit resolver for it | ||
var typeName = utils_1.getModifiedTsTypeName(utils_1.getTypeRef(field), this.options.typePrefix); | ||
var argsType = '{}'; | ||
if (field.args.length > 0) { | ||
return; | ||
// Generated in resolver-generator.ts. (TODO: Merge) | ||
argsType = objectType.name + "_" + uppercaseFisrtFieldName + "_Args"; | ||
} | ||
var typeName = utils_1.getModifiedTsTypeName(utils_1.getTypeRef(field), this.options.typePrefix); | ||
return [field.name + "?: " + typeName]; | ||
// Generated in resolver-generator.ts | ||
var contextType = this.options.resolver && this.options.resolver.contextType || 'Context'; | ||
return [field.name + "?: GQLProperty<" + typeName + ", " + argsType + ", " + contextType + ">"]; | ||
}; | ||
@@ -257,0 +270,0 @@ return ModelsGenerator; |
@@ -79,21 +79,3 @@ "use strict"; | ||
'', | ||
'/**', | ||
' * Technically a property can be a function also. We DO NOT support this use case', | ||
' * because it does not feel like a good coding pattern to put resolver-like functions', | ||
' * on to of the object itself. If needed, property with getter can be used', | ||
' * which takes the property of the source object of the same name as the field', | ||
" * and returns it as the Value, or if it's a function, returns the Value", | ||
' * of calling that function while passing along args, context and info.', | ||
' * NOTE how the function signature does not have parent', | ||
' */', | ||
'export type GQLProperty<T, Args, Ctx> = T | Promise<T> // | ((args: Args, context: Ctx, info: GraphQLResolveInfo) => T | Promise<T>)', | ||
'', | ||
'export type GQLResolver<T, P, Args, Ctx> = (parent: P, args: Args, context: Ctx, info: GraphQLResolveInfo) => T | Promise<T>', | ||
'/**', | ||
' * When used as properties of the return value of an existing resolver, this really should be', | ||
' * Value<T> instead -> So resolvers should not be returning other resolver-like objects', | ||
' * In practice the implementation "sort of" allows it (see above)', | ||
' * TODO: Finish correct type def for model separate from resolver', | ||
' */', | ||
'export type GQLPropertyOrResolver<T, P, Args, Ctx> = GQLProperty<T, Args, Ctx> | GQLResolver<T, P, Args, Ctx>', | ||
'', | ||
@@ -100,0 +82,0 @@ 'export type GQLTypeResolver<P, Ctx, T> = ', |
{ | ||
"name": "@beamf/graphql-schema-typescript", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "Generate TypeScript from GraphQL's schema type definitions", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
232507
6415