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


TypeScript GraphQLSchema.getTypeMap方法代码示例

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


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

示例1: checkForResolveTypeResolver

// If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers
function checkForResolveTypeResolver(
  schema: GraphQLSchema,
  requireResolversForResolveType?: boolean,
) {
  Object.keys(schema.getTypeMap())
    .map(typeName => schema.getType(typeName))
    .forEach((type: GraphQLUnionType | GraphQLInterfaceType) => {
      if (
        !(
          type instanceof GraphQLUnionType ||
          type instanceof GraphQLInterfaceType
        )
      ) {
        return;
      }
      if (!type.resolveType) {
        if (requireResolversForResolveType === false) {
          return;
        }
        if (requireResolversForResolveType === true) {
          throw new SchemaError(
            `Type "${type.name}" is missing a "resolveType" resolver`,
          );
        }
        // tslint:disable-next-line:max-line-length
        console.warn(
          `Type "${
            type.name
          }" is missing a "__resolveType" resolver. Pass false into `  +
          `"resolverValidationOptions.requireResolversForResolveType" to disable this warning.`,
        );
      }
    });
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:35,代码来源:checkForResolveTypeResolver.ts

示例2: getTypeNames

export function getTypeNames(ast: GraphQLSchema) {
  // Create types
  return Object.keys(ast.getTypeMap())
    .filter(typeName => !typeName.startsWith('__'))
    .filter(typeName => typeName !== (ast.getQueryType() as any).name)
    .filter(
      typeName =>
        ast.getMutationType()
          ? typeName !== (ast.getMutationType()! as any).name
          : true,
    )
    .filter(
      typeName =>
        ast.getSubscriptionType()
          ? typeName !== (ast.getSubscriptionType()! as any).name
          : true,
    )
    .sort(
      (a, b) =>
        (ast.getType(a) as any).constructor.name <
        (ast.getType(b) as any).constructor.name
          ? -1
          : 1,
    )
}
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:25,代码来源:getTypeNames.ts

示例3: extendResolversFromInterfaces

function extendResolversFromInterfaces(
  schema: GraphQLSchema,
  resolvers: IResolvers,
) {
  const typeNames = Object.keys({
    ...schema.getTypeMap(),
    ...resolvers,
  });

  const extendedResolvers: IResolvers = {};
  typeNames.forEach(typeName => {
    const typeResolvers = resolvers[typeName];
    const type = schema.getType(typeName);
    if (type instanceof GraphQLObjectType) {
      const interfaceResolvers = type
        .getInterfaces()
        .map(iFace => resolvers[iFace.name]);
      extendedResolvers[typeName] = Object.assign(
        {},
        ...interfaceResolvers,
        typeResolvers,
      );
    } else {
      if (typeResolvers) {
        extendedResolvers[typeName] = typeResolvers;
      }
    }
  });

  return extendedResolvers;
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:31,代码来源:extendResolversFromInterfaces.ts

示例4: forEachField

function forEachField(schema: GraphQLSchema, fn: FieldIteratorFn): void {
  const typeMap = schema.getTypeMap();
  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,代码行数:14,代码来源:index.ts

示例5: visitSchema

export function visitSchema(
  schema: GraphQLSchema,
  visitor: SchemaVisitor,
  stripResolvers?: boolean,
) {
  const types = {};
  const resolveType = createResolveType(name => {
    if (typeof types[name] === 'undefined') {
      throw new Error(`Can't find type ${name}.`);
    }
    return types[name];
  });
  const queryType = schema.getQueryType();
  const mutationType = schema.getMutationType();
  const subscriptionType = schema.getSubscriptionType();
  const typeMap = schema.getTypeMap();
  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);
      }
    }
  });
  return new GraphQLSchema({
    query: queryType ? (types[queryType.name] as GraphQLObjectType) : null,
    mutation: mutationType
      ? (types[mutationType.name] as GraphQLObjectType)
      : null,
    subscription: subscriptionType
      ? (types[subscriptionType.name] as GraphQLObjectType)
      : null,
    types: Object.keys(types).map(name => types[name]),
  });
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:49,代码来源:visitSchema.ts

示例6: extractPossibleTypes

function extractPossibleTypes(
  transformedSchema: GraphQLSchema,
  targetSchema: GraphQLSchema,
) {
  const typeMap = transformedSchema.getTypeMap();
  const mapping: TypeMapping = {};
  Object.keys(typeMap).forEach(typeName => {
    const type = typeMap[typeName];
    if (isAbstractType(type)) {
      const targetType = targetSchema.getType(typeName);
      if (!isAbstractType(targetType)) {
        const implementations = transformedSchema.getPossibleTypes(type) || [];
        mapping[typeName] = implementations
          .filter(impl => targetSchema.getType(impl.name))
          .map(impl => impl.name);
      }
    }
  });
  return mapping;
}
开发者ID:apollostack,项目名称:graphql-tools,代码行数:20,代码来源:ExpandAbstractTypes.ts


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