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