當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript types.GetChildSelectionsType類代碼示例

本文整理匯總了TypeScript中@gql2ts/types.GetChildSelectionsType的典型用法代碼示例。如果您正苦於以下問題:TypeScript GetChildSelectionsType類的具體用法?TypeScript GetChildSelectionsType怎麽用?TypeScript GetChildSelectionsType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GetChildSelectionsType類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: GenerateSubtypeCache


//.........這裏部分代碼省略.........
        throw new Error('Unsupported Operation');
    }
  };

  const wrapPossiblePartial: (possiblePartial: IChildSelection) => string = possiblePartial => {
    if (possiblePartial.isPartial) {
      return wrapPartial(possiblePartial.iface);
    } else {
      return possiblePartial.iface;
    }
  };

  const flattenComplexTypes: (children: IChildSelection[]) => IComplexTypeSignature[] = children => (
    children.reduce((acc, child) => { acc.push(...child.complexTypes); return acc; }, [] as IComplexTypeSignature[])
  );

  type GetField = (operation: OperationTypeNode, selection: FieldNode, parent?: GraphQLType) => GraphQLField<any, any>;
  const getField: GetField = (operation, selection, parent) => {
    if (parent && isCompositeType(parent)) {
      if (parent instanceof GraphQLUnionType) {
        return parent.getTypes().map(t => t.getFields()[selection.name.value]).find(z => !!z)!;
      } else {
        return parent.getFields()[selection.name.value];
      }
    } else {
      const operationFields: GraphQLObjectType | null | undefined = getOperationFields(operation);
      // operation is taken from the schema, so it should never be falsy
      return operationFields!.getFields()[selection.name.value];
    }
  };

  const rootIntrospectionTypes: Map<string, string> = new Map([[ '__schema', '__Schema' ], [ '__type', '__Type' ]]);

  const getChildSelections: GetChildSelectionsType = (operation, selection, parent?, isUndefined = false): IChildSelection => {
    let str: string = '';
    let isFragment: boolean = false;
    let isPartial: boolean = false;
    let complexTypes: IComplexTypeSignature[] = [];
    if (selection.kind === 'Field') {
      const field: GraphQLField<any, any> = getField(operation, selection, parent);
      const originalName: string = selection.name.value;
      const selectionName: string = selection.alias ? selection.alias.value : originalName;
      let childType: string | undefined;

      isUndefined = isUndefined || isUndefinedFromDirective(selection.directives);
      let resolvedType: string;
      if (originalName === '__typename') {
        if (!parent) {
          resolvedType = TypeMap.String;
        } else if (isAbstractType(parent)) {
          const possibleTypes: GraphQLObjectType[] = parsedSchema.getPossibleTypes(parent);
          /**
           * @TODO break this OR logic out of here (and the other places) and put into a printer
           * @TODO break out the string-literal type out of here as it probably isn't supported by other languages
           */
          resolvedType = possibleTypes.map(({ name }) => `'${name}'`).join(' | ');
        } else {
          resolvedType = `'${parent.toString()}'`;
        }
      } else if (!!selection.selectionSet) {
        let newParent: GraphQLCompositeType | undefined;
        const fieldType: GraphQLNamedType = rootIntrospectionTypes.has(originalName) ? parsedSchema.getType(
          rootIntrospectionTypes.get(originalName)!
        ) : getNamedType(field.type);
        if (isCompositeType(fieldType)) {
          newParent = fieldType;
開發者ID:avantcredit,項目名稱:gql2ts,代碼行數:67,代碼來源:index.ts

示例2: getChildSelections

 const ret: IChildSelection[] = def.selectionSet.selections.map(sel => getChildSelections('query', sel, foundType));
開發者ID:avantcredit,項目名稱:gql2ts,代碼行數:1,代碼來源:index.ts


注:本文中的@gql2ts/types.GetChildSelectionsType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。