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

TypeScript graphql.getNullableType函数代码示例

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

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



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

示例1: getGqlInputType

  function defaultCase <TKey>(keyType: Type<TKey>): CollectionKeyInputHelpers<TKey> {
    const fieldName = formatName.arg(collectionKey.name)
    const { gqlType, fromGqlInput } = getGqlInputType(buildToken, keyType)

    return {
      fieldEntries: [
        [fieldName, {
          description: `The ${scrib.type(gqlType)} to use when reading a single value.`,
          type: new GraphQLNonNull(getNullableType(gqlType)),
        }],
      ],
      getKeyFromInput: fromGqlInput,
    }
  }
开发者ID:tim-field,项目名称:postgraphql,代码行数:14,代码来源:createCollectionKeyInputHelpers.ts


示例2: mock

  public mock(
    root: any,
    args: { [key: string]: any },
    context: any,
    info: GraphQLResolveInfo,
    fieldType: GraphQLList<any>,
    mockTypeFunc: IMockTypeFn,
  ) {
    let arr: any[];
    if (Array.isArray(this.len)) {
      arr = new Array(this.randint(this.len[0], this.len[1]));
    } else {
      arr = new Array(this.len);
    }

    for (let i = 0; i < arr.length; i++) {
      if (typeof this.wrappedFunction === 'function') {
        const res = this.wrappedFunction(root, args, context, info);
        if (res instanceof MockList) {
          const nullableType = getNullableType(fieldType.ofType) as GraphQLList<
            any
          >;
          arr[i] = res.mock(
            root,
            args,
            context,
            info,
            nullableType,
            mockTypeFunc,
          );
        } else {
          arr[i] = res;
        }
      } else {
        arr[i] = mockTypeFunc(fieldType.ofType)(root, args, context, info);
      }
    }
    return arr;
  }
开发者ID:sventschui,项目名称:graphql-tools,代码行数:39,代码来源:mock.ts


示例3: 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


示例4: 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


示例5: getQueryGqlType

 resolveType: (value: {}) => value === $$isQuery ? getQueryGqlType(buildToken) : getNullableType(value[$$nodeType]),
开发者ID:tim-field,项目名称:postgraphql,代码行数:1,代码来源:getNodeInterfaceType.ts


示例6: GraphQLNonNull

 ({ name, gqlType }) =>
   [formatName.arg(name), {
     // No description…
     type: pgProcedure.isStrict ? new GraphQLNonNull(getNullableType(gqlType)) : gqlType,
   }],
开发者ID:tim-field,项目名称:postgraphql,代码行数:5,代码来源:createPgProcedureObjectTypeGqlFieldEntry.ts


示例7: buildObject

 fields: buildObject(fieldFixtures.map(({ key, field, gqlType }) => ({
   key,
   value: {
     description: field.description,
     type: field.hasDefault ? getNullableGqlType(gqlType) : gqlType,
   },
 }))),
开发者ID:tim-field,项目名称:postgraphql,代码行数:7,代码来源:getGqlInputType.ts


示例8: getGqlInputType

 nullable: <TNonNullValue>(type: NullableType<TNonNullValue>): GetGqlInputReturn<TNonNullValue | null> => {
   const { gqlType: nonNullGqlType, fromGqlInput: fromNonNullGqlInput } = getGqlInputType(buildToken, type.nonNullType)
   return {
     gqlType: getNullableGqlType(nonNullGqlType),
     fromGqlInput: gqlInput =>
       gqlInput == null
         ? null
         : fromNonNullGqlInput(gqlInput),
   }
 },
开发者ID:tim-field,项目名称:postgraphql,代码行数:10,代码来源:getGqlInputType.ts


示例9: getGqlOutputType

 nullable: <TNonNullValue>(type: NullableType<TNonNullValue>): GetGqlOutputTypeReturn<TNonNullValue | null> => {
   const { gqlType: nonNullGqlType, intoGqlOutput: intoNonNullGqlOutput } = getGqlOutputType(buildToken, type.nonNullType)
   return {
     gqlType: getNullableGqlType(nonNullGqlType),
     intoGqlOutput: value =>
       type.isNonNull(value)
         ? intoNonNullGqlOutput(value)
         : null,
   }
 },
开发者ID:tim-field,项目名称:postgraphql,代码行数:10,代码来源:getGqlOutputType.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript graphql.getOperationAST函数代码示例发布时间:2022-05-25
下一篇:
TypeScript graphql.getNamedType函数代码示例发布时间: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