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

TypeScript graphql.buildSchema函数代码示例

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

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



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

示例1: valueToSchema

function valueToSchema(
  schema: GraphQLSchema | string | Source | IntrospectionResult,
): GraphQLSchema {
  if (schema instanceof GraphQLSchema) {
    return schema
  } else if (typeof schema === 'string') {
    return buildSchema(schema)
  } else if (schema instanceof Source) {
    return buildSchema(schema)
  } else if (typeof schema === 'object' && !Array.isArray(schema)) {
    return introspectionToSchema(schema as IntrospectionResult)
  }
  throw new Error('Can not convert data to a schema')
}
开发者ID:graphcool,项目名称:graphql-config,代码行数:14,代码来源:utils.ts


示例2: it

  it('should override the scope from the target type with that specified on a field', async () => {
    const schema = buildSchema(`
      type Query {
        droid(id: ID!): Droid @cacheControl(scope: PRIVATE)
      }

      type Droid @cacheControl(maxAge: 60, scope: PUBLIC) {
        id: ID!
        name: String!
      }
    `);

    const hints = await collectCacheControlHints(
      schema,
      `
        query {
          droid(id: 2001) {
            name
          }
        }
      `,
      { defaultMaxAge: 10 },
    );

    expect(hints).toContainEqual({
      path: ['droid'],
      maxAge: 60,
      scope: CacheScope.Private,
    });
  });
开发者ID:simonjoom,项目名称:react-native-project,代码行数:30,代码来源:cacheControlDirective.ts


示例3: graphQLTypes

export async function graphQLTypes(): Promise<void> {
    const schemaStr = await readFile(GRAPHQL_SCHEMA_PATH, 'utf8')
    const schema = buildSchema(schemaStr)
    const result = (await graphql(schema, introspectionQuery)) as { data: IntrospectionQuery }

    const formatOptions = (await resolveConfig(__dirname, { config: __dirname + '/../prettier.config.js' }))!
    const typings =
        'export type ID = string\n\n' +
        generateNamespace(
            '',
            result,
            {
                typeMap: {
                    ...DEFAULT_TYPE_MAP,
                    ID: 'ID',
                },
            },
            {
                generateNamespace: (name: string, interfaces: string) => interfaces,
                interfaceBuilder: (name: string, body: string) =>
                    'export ' + DEFAULT_OPTIONS.interfaceBuilder(name, body),
                enumTypeBuilder: (name: string, values: string) =>
                    'export ' + DEFAULT_OPTIONS.enumTypeBuilder(name, values),
                typeBuilder: (name: string, body: string) => 'export ' + DEFAULT_OPTIONS.typeBuilder(name, body),
                wrapList: (type: string) => `${type}[]`,
                postProcessor: (code: string) => format(code, { ...formatOptions, parser: 'typescript' }),
            }
        )
    await writeFile(__dirname + '/src/graphql/schema.ts', typings)
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:30,代码来源:gulpfile.ts


示例4: function

export const jsSchemaLoader: SchemaLoader = async function (options: TJsSchemaLoaderOptions) {

    const schemaPath = resolve(options.schemaFile);
    let schemaModule = require(schemaPath);
    let schema: string;

    // check if exist default in module
    if (typeof schemaModule === 'object') {
        schemaModule = schemaModule.default
    }

    // check for array of definition
    if (Array.isArray(schemaModule)){
        schema = schemaModule.join('');

    // check for array array wrapped in a function
    } else if  (typeof schemaModule === 'function')  {
        schema = schemaModule().join('');

    } else {
        throw new Error(`Unexpected schema definition on "${schemaModule}", must be an array or function`)
    }

    const introspection = await execute(
        buildSchema(schema),
        parse(introspectionQuery)
    ) as Introspection;

    return introspection.data.__schema;
};
开发者ID:2fd,项目名称:graphdoc,代码行数:30,代码来源:js.ts


示例5: test

test('typescript definition generator', t => {
  const schema = buildSchema(typeDefs)
  const generator = new JavascriptGenerator({
    schema,
  })
  const javascript = generator.renderJavascript()
  t.snapshot(javascript)
})
开发者ID:nunsie,项目名称:prisma,代码行数:8,代码来源:javascript-client.test.ts


示例6: test

test('typescript generator', t => {
  const schema = buildSchema(typeDefs)
  const generator = new TypescriptGenerator({
    schema,
  })
  const result = generator.render()
  t.snapshot(result)
})
开发者ID:nunsie,项目名称:prisma,代码行数:8,代码来源:typescript-client.test.ts


示例7: test

test('typescript generator - embedded', t => {
  const schema = buildSchema(typeDefs)
  const generator = new TypescriptGenerator({
    schema,
    internalTypes: parseInternalTypes(datamodel, DatabaseType.postgres).types,
  })
  const result = generator.render()
  t.snapshot(result)
})
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:9,代码来源:typescript-client.embedded.test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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