當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript graphql.buildSchema函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。