本文整理汇总了TypeScript中graphql.GraphQLNamedType.getInterfaces方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLNamedType.getInterfaces方法的具体用法?TypeScript GraphQLNamedType.getInterfaces怎么用?TypeScript GraphQLNamedType.getInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.GraphQLNamedType
的用法示例。
在下文中一共展示了GraphQLNamedType.getInterfaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: recreateType
export function recreateType(
type: GraphQLNamedType,
resolveType: ResolveType<any>,
keepResolvers: boolean,
): GraphQLNamedType {
if (type instanceof GraphQLObjectType) {
const fields = type.getFields();
const interfaces = type.getInterfaces();
return new GraphQLObjectType({
name: type.name,
description: type.description,
astNode: type.astNode,
isTypeOf: keepResolvers ? type.isTypeOf : undefined,
fields: () =>
fieldMapToFieldConfigMap(fields, resolveType, keepResolvers),
interfaces: () => interfaces.map(iface => resolveType(iface)),
});
} else if (type instanceof GraphQLInterfaceType) {
const fields = type.getFields();
return new GraphQLInterfaceType({
name: type.name,
description: type.description,
astNode: type.astNode,
fields: () =>
fieldMapToFieldConfigMap(fields, resolveType, keepResolvers),
resolveType: keepResolvers
? type.resolveType
: (parent, context, info) =>
resolveFromParentTypename(parent, info.schema),
});
} else if (type instanceof GraphQLUnionType) {
return new GraphQLUnionType({
name: type.name,
description: type.description,
astNode: type.astNode,
types: () => type.getTypes().map(unionMember => resolveType(unionMember)),
resolveType: keepResolvers
? type.resolveType
: (parent, context, info) =>
resolveFromParentTypename(parent, info.schema),
});
} else if (type instanceof GraphQLInputObjectType) {
return new GraphQLInputObjectType({
name: type.name,
description: type.description,
astNode: type.astNode,
fields: () =>
inputFieldMapToFieldConfigMap(type.getFields(), resolveType),
});
} else if (type instanceof GraphQLEnumType) {
const values = type.getValues();
const newValues = {};
values.forEach(value => {
newValues[value.name] = {
value: value.value,
deprecationReason: value.deprecationReason,
description: value.description,
astNode: value.astNode,
};
});
return new GraphQLEnumType({
name: type.name,
description: type.description,
astNode: type.astNode,
values: newValues,
});
} else if (type instanceof GraphQLScalarType) {
if (keepResolvers || isSpecifiedScalarType(type)) {
return type;
} else {
return new GraphQLScalarType({
name: type.name,
description: type.description,
astNode: type.astNode,
serialize(value: any) {
return value;
},
parseValue(value: any) {
return value;
},
parseLiteral(ast: ValueNode) {
return parseLiteral(ast);
},
});
}
} else {
throw new Error(`Invalid type ${type}`);
}
}