本文整理匯總了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}`);
}
}