Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
fix(gg): generate flow-type union type resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Jan 21, 2019
1 parent b495742 commit ccbc90e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/graphqlgen/src/generators/flow-generator.ts
Expand Up @@ -6,6 +6,7 @@ import {
GraphQLTypeField,
GraphQLTypeObject,
GraphQLTypeArgument,
GraphQLUnionObject,
} from '../source-helper'
import { upperFirst } from '../utils'
import {
Expand Down Expand Up @@ -133,7 +134,7 @@ function renderNamespaces(
typeToInputTypeAssociation: TypeToInputTypeAssociation,
inputTypesMap: InputTypesMap,
): string {
return args.types
const objectNamespaces = args.types
.filter(type => type.type.isObject)
.map(type =>
renderNamespace(
Expand All @@ -146,6 +147,12 @@ function renderNamespaces(
),
)
.join(os.EOL)

return `\
${objectNamespaces}
${renderUnionNamespaces(args)}
`
}

function renderNamespace(
Expand Down Expand Up @@ -193,6 +200,23 @@ function renderNamespace(
`
}

function renderUnionNamespaces(args: GenerateArgs): string {
return args.unions.map(type => renderUnionNamespace(type, args)).join(os.EOL)
}

function renderUnionNamespace(
graphQLTypeObject: GraphQLUnionObject,
args: GenerateArgs,
): string {
return `\
export interface ${graphQLTypeObject.name}_Resolvers {
__resolveType?: GraphQLTypeResolver<${graphQLTypeObject.types
.map(interfaceType => getModelName(interfaceType, args.modelMap))
.join(' | ')}, ${getContextName(args.context)}>;
}
`
}

function renderInputTypeInterfaces(
type: GraphQLTypeObject,
modelMap: ModelMap,
Expand Down
Expand Up @@ -718,6 +718,10 @@ export interface User_Resolvers {
) => string | Promise<string>;
}
export interface UserType_Resolvers {
__resolveType?: GraphQLTypeResolver<Student | Professor, Context>;
}
export interface Resolvers {
Query: Query_Resolvers;
Student: Student_Resolvers;
Expand Down

0 comments on commit ccbc90e

Please sign in to comment.