• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript graphql.getNamedType函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中graphql.getNamedType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getNamedType函数的具体用法?TypeScript getNamedType怎么用?TypeScript getNamedType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getNamedType函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: resolveType

 const resolveType = <T extends GraphQLType>(type: T): T | GraphQLType => {
   if (type instanceof GraphQLList) {
     const innerType = resolveType(type.ofType);
     if (innerType === null) {
       return null;
     } else {
       return new GraphQLList(innerType) as T;
     }
   } else if (type instanceof GraphQLNonNull) {
     const innerType = resolveType(type.ofType);
     if (innerType === null) {
       return null;
     } else {
       return new GraphQLNonNull(innerType) as T;
     }
   } else if (isNamedType(type)) {
     const typeName = getNamedType(type).name;
     switch (typeName) {
       case GraphQLInt.name:
         return GraphQLInt;
       case GraphQLFloat.name:
         return GraphQLFloat;
       case GraphQLString.name:
         return GraphQLString;
       case GraphQLBoolean.name:
         return GraphQLBoolean;
       case GraphQLID.name:
         return GraphQLID;
       default:
         return getType(typeName, type);
     }
   } else {
     return type;
   }
 };
开发者ID:apollostack,项目名称:graphql-tools,代码行数:35,代码来源:schemaRecreation.ts


示例2: isNamedType

 Object.keys(typeMap).forEach(typeName => {
   const type: GraphQLType = typeMap[typeName];
   if (
     isNamedType(type) &&
     getNamedType(type).name.slice(0, 2) !== '__' &&
     type !== queryType &&
     type !== mutationType
   ) {
     let newType;
     if (isCompositeType(type) || type instanceof GraphQLInputObjectType) {
       newType = recreateCompositeType(schema, type, typeRegistry);
     } else {
       newType = getNamedType(type);
     }
     typeRegistry.addType(newType.name, newType, onTypeConflict);
   }
 });
开发者ID:sventschui,项目名称:graphql-tools,代码行数:17,代码来源:mergeSchemas.ts


示例3: fn

  Object.keys(typeMap).forEach(typeName => {
    const type = typeMap[typeName];

    if (!getNamedType(type).name.startsWith('__') && type instanceof GraphQLObjectType) {
      const fields = type.getFields();
      Object.keys(fields).forEach(fieldName => {
        const field = fields[fieldName];
        fn(field, typeName, fieldName);
      });
    }
  });
开发者ID:pluwum,项目名称:hacker_news_clone,代码行数:11,代码来源:index.ts


示例4: GraphQLList

 public resolveType<T extends GraphQLType>(type: T): T {
   if (type instanceof GraphQLList) {
     return new GraphQLList(this.resolveType(type.ofType)) as T;
   } else if (type instanceof GraphQLNonNull) {
     return new GraphQLNonNull(this.resolveType(type.ofType)) as T;
   } else if (isNamedType(type)) {
     return this.getType(getNamedType(type).name) as T;
   } else {
     return type;
   }
 }
开发者ID:sventschui,项目名称:graphql-tools,代码行数:11,代码来源:TypeRegistry.ts


示例5: getTypeName

  /**
   * Gets the standard GraphQL type string representation.
   *
   * @private
   */
  function getTypeName (type: GraphQLType): string {
    // Return an empty string for tests.
    if (type == null) return ''
    // If this is a named type, just return the type’s name.
    if (type === getNamedType(type)) return type.name
    // If this is non-null return the nullable type’s name.
    if (type instanceof GraphQLNonNull) return getTypeName(type.ofType)
    // If this is a list, wrap the name with `[]`.
    if (type instanceof GraphQLList) return `[${getTypeName(type.ofType)}]`

    throw new Error('Unrecognized unnamed GraphQL type.')
  }
开发者ID:tim-field,项目名称:postgraphql,代码行数:17,代码来源:scrib.ts


示例6: fn

  Object.keys(typeMap).forEach(typeName => {
    const type = typeMap[typeName];

    // TODO: maybe have an option to include these?
    if (
      !getNamedType(type).name.startsWith('__') &&
      type instanceof GraphQLObjectType
    ) {
      const fields = type.getFields();
      Object.keys(fields).forEach(fieldName => {
        const field = fields[fieldName];
        fn(field, typeName, fieldName);
      });
    }
  });
开发者ID:apollostack,项目名称:graphql-tools,代码行数:15,代码来源:forEachField.ts


示例7: forEachField

  forEachField(schema, (field, typeName, fieldName) => {
    // requires a resolve function for *every* field.
    if (requireResolversForAllFields) {
      expectResolveFunction(field, typeName, fieldName);
    }

    // requires a resolve function on every field that has arguments
    if (requireResolversForArgs && field.args.length > 0) {
      expectResolveFunction(field, typeName, fieldName);
    }

    // requires a resolve function on every field that returns a non-scalar type
    if (
      requireResolversForNonScalar &&
      !(getNamedType(field.type) instanceof GraphQLScalarType)
    ) {
      expectResolveFunction(field, typeName, fieldName);
    }
  });
开发者ID:apollostack,项目名称:graphql-tools,代码行数:19,代码来源:assertResolveFunctionsPresent.ts


示例8: getTypeSpecifiers

 Object.keys(typeMap).map((typeName: string) => {
   const type = typeMap[typeName];
   if (isNamedType(type) && getNamedType(type).name.slice(0, 2) !== '__') {
     const specifiers = getTypeSpecifiers(type, schema);
     const typeVisitor = getVisitor(visitor, specifiers);
     if (typeVisitor) {
       const result: GraphQLNamedType | null | undefined = typeVisitor(
         type,
         schema,
       );
       if (typeof result === 'undefined') {
         types[typeName] = recreateType(type, resolveType, !stripResolvers);
       } else if (result === null) {
         types[typeName] = null;
       } else {
         types[typeName] = recreateType(result, resolveType, !stripResolvers);
       }
     } else {
       types[typeName] = recreateType(type, resolveType, !stripResolvers);
     }
   }
 });
开发者ID:apollostack,项目名称:graphql-tools,代码行数:22,代码来源:visitSchema.ts


示例9: assignResolveType

  function assignResolveType(type: GraphQLType) {
    const fieldType = getNullableType(type);
    const namedFieldType = getNamedType(fieldType);

    const oldResolveType = getResolveType(namedFieldType);
    if (preserveResolvers && oldResolveType && oldResolveType.length) {
      return;
    }

    if (
      namedFieldType instanceof GraphQLUnionType ||
      namedFieldType instanceof GraphQLInterfaceType
    ) {
      // the default `resolveType` always returns null. We add a fallback
      // resolution that works with how unions and interface are mocked
      namedFieldType.resolveType = (
        data: any,
        context: any,
        info: GraphQLResolveInfo,
      ) => {
        return info.schema.getType(data.__typename) as GraphQLObjectType;
      };
    }
  }
开发者ID:sventschui,项目名称:graphql-tools,代码行数:24,代码来源:mock.ts


示例10: return

    return (
      root: any,
      args: { [key: string]: any },
      context: any,
      info: GraphQLResolveInfo,
    ): any => {
      // nullability doesn't matter for the purpose of mocking.
      const fieldType = getNullableType(type);
      const namedFieldType = getNamedType(fieldType);

      if (root && typeof root[fieldName] !== 'undefined') {
        let result: any;

        // if we're here, the field is already defined
        if (typeof root[fieldName] === 'function') {
          result = root[fieldName](root, args, context, info);
          if (result instanceof MockList) {
            result = result.mock(
              root,
              args,
              context,
              info,
              fieldType as GraphQLList<any>,
              mockType,
            );
          }
        } else {
          result = root[fieldName];
        }

        // Now we merge the result with the default mock for this type.
        // This allows overriding defaults while writing very little code.
        if (mockFunctionMap.has(namedFieldType.name)) {
          result = mergeMocks(
            mockFunctionMap
              .get(namedFieldType.name)
              .bind(null, root, args, context, info),
            result,
          );
        }
        return result;
      }

      if (fieldType instanceof GraphQLList) {
        return [
          mockType(fieldType.ofType)(root, args, context, info),
          mockType(fieldType.ofType)(root, args, context, info),
        ];
      }
      if (
        mockFunctionMap.has(fieldType.name) &&
        !(
          fieldType instanceof GraphQLUnionType ||
          fieldType instanceof GraphQLInterfaceType
        )
      ) {
        // the object passed doesn't have this field, so we apply the default mock
        return mockFunctionMap.get(fieldType.name)(root, args, context, info);
      }
      if (fieldType instanceof GraphQLObjectType) {
        // objects don't return actual data, we only need to mock scalars!
        return {};
      }
      // if a mock function is provided for unionType or interfaceType, execute it to resolve the concrete type
      // otherwise randomly pick a type from all implementation types
      if (
        fieldType instanceof GraphQLUnionType ||
        fieldType instanceof GraphQLInterfaceType
      ) {
        let implementationType;
        if (mockFunctionMap.has(fieldType.name)) {
          const interfaceMockObj = mockFunctionMap.get(fieldType.name)(
            root,
            args,
            context,
            info,
          );
          if (!interfaceMockObj || !interfaceMockObj.__typename) {
            return Error(`Please return a __typename in "${fieldType.name}"`);
          }
          implementationType = schema.getType(interfaceMockObj.__typename);
        } else {
          const possibleTypes = schema.getPossibleTypes(fieldType);
          implementationType = getRandomElement(possibleTypes);
        }
        return Object.assign(
          { __typename: implementationType },
          mockType(implementationType)(root, args, context, info),
        );
      }

      if (fieldType instanceof GraphQLEnumType) {
        return getRandomElement(fieldType.getValues()).value;
      }

      if (defaultMockMap.has(fieldType.name)) {
        return defaultMockMap.get(fieldType.name)(root, args, context, info);
      }

      // if we get to here, we don't have a value, and we don't have a mock for this type,
//.........这里部分代码省略.........
开发者ID:sventschui,项目名称:graphql-tools,代码行数:101,代码来源:mock.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript graphql.getNullableType函数代码示例发布时间:2022-05-25
下一篇:
TypeScript graphql.formatError函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap