當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。