当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript GraphQLNamedType.getValues方法代码示例

本文整理汇总了TypeScript中graphql.GraphQLNamedType.getValues方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLNamedType.getValues方法的具体用法?TypeScript GraphQLNamedType.getValues怎么用?TypeScript GraphQLNamedType.getValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphql.GraphQLNamedType的用法示例。


在下文中一共展示了GraphQLNamedType.getValues方法的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}`);
  }
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:93,代码来源:schemaRecreation.ts


注:本文中的graphql.GraphQLNamedType.getValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。