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

TypeScript graphql-tools.addMockFunctionsToSchema函数代码示例

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

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



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

示例1: test

test('trace construction', async () => {
  const typeDefs = `
  type User {
    id: Int
    name: String
    posts(limit: Int): [Post]
  }

  type Post {
    id: Int
    title: String
    views: Int
    author: User
  }

  type Query {
    aString: String
    aBoolean: Boolean
    anInt: Int
    author(id: Int): User
    topPosts(limit: Int): [Post]
  }
`;

  const query = `
    query q {
      author(id: 5) {
        name
        posts(limit: 2) {
          id
        }
      }
      aBoolean
    }
`;

  const schema = makeExecutableSchema({ typeDefs });
  addMockFunctionsToSchema({ schema });
  enableGraphQLExtensions(schema);

  const traces: Array<any> = [];
  function addTrace(signature: string, operationName: string, trace: Trace) {
    traces.push({ signature, operationName, trace });
  }
  const reportingExtension = new EngineReportingExtension({}, addTrace);
  const stack = new GraphQLExtensionStack([reportingExtension]);
  const requestDidEnd = stack.requestDidStart({
    request: new Request('http://localhost:123/foo') as any,
    queryString: query,
  });
  await graphql({
    schema,
    source: query,
    contextValue: { _extensionStack: stack },
  });
  requestDidEnd();
  // XXX actually write some tests
});
开发者ID:simonjoom,项目名称:react-native-project,代码行数:58,代码来源:extension.test.ts


示例2: createSchemeWithAccounts

export function createSchemeWithAccounts(accountsServer) {
  const accountsGraphQL = createJSAccountsGraphQL(accountsServer);

  // TODO after accounts pr remove dummy object
  const mockResolvers = {
    Query: {},
    Mutation: {},
    ...subscriptionResolver
  };
  const resolversWithAccounts = accountsGraphQL.extendWithResolvers(mockResolvers);

  const executableSchema = makeExecutableSchema({
    typeDefs: [schema, accountsGraphQL.schema],
    resolvers: resolversWithAccounts,
    logger: { log: (e) => console.log(e) },
  });

  addMockFunctionsToSchema({ schema: executableSchema, mocks,  preserveResolvers: true});

  return executableSchema;
}
开发者ID:RocketChat,项目名称:Rocket.Chat.PWA,代码行数:21,代码来源:schema.ts


示例3: it

it("resolves an Artist on a Consignment Submission", async () => {
  const allMergedSchemas = await mergeSchemas()

  // This test is that a submission gets the artist by stitching a MP
  // Artist into the ConsignmentSubmission inside the schema
  const query = gql`
    {
      submission(id: 123) {
        artist_id
        artist {
          name
        }
      }
    }
  `

  // Mock the resolvers for just a submission, and an artist.
  // The part we are testing is the step that goes from a submission
  // to the Artist
  addMockFunctionsToSchema({
    schema: allMergedSchemas,
    mocks: {
      Query: () => ({
        submission: (_root, _params) => {
          return { artist_id: "321" }
        },
      }),
    },
  })

  const result = await graphql(allMergedSchemas, query, {
    accessToken: null,
    userID: null,
  })

  expect(result).toEqual({
    data: { submission: { artist: { name: "Hello World" }, artist_id: "321" } },
  })
})
开发者ID:xtina-starr,项目名称:metaphysics,代码行数:39,代码来源:stitching.test.ts


示例4: compose

export function compose(): AppFrontendLibs {
  const appModule = uiModules.get('app/siem');
  const observableApi = new AppKibanaObservableApiAdapter({
    basePath: chrome.getBasePath(),
    xsrfToken: chrome.getXsrfToken(),
  });
  const framework = new AppKibanaFrameworkAdapter(appModule, uiRoutes, timezoneProvider);
  const typeDefs = `
  Query {}
`;

  const mocks = {
    Mutation: () => undefined,
    Query: () => undefined,
  };

  const schema = makeExecutableSchema({ typeDefs });
  addMockFunctionsToSchema({
    mocks,
    schema,
  });

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const cache = new InMemoryCache((window as any).__APOLLO_CLIENT__);

  const apolloClient = new ApolloClient({
    cache,
    link: new SchemaLink({ schema }),
  });

  const libs: AppFrontendLibs = {
    apolloClient,
    framework,
    observableApi,
  };
  return libs;
}
开发者ID:,项目名称:,代码行数:37,代码来源:


示例5: require

import { GraphQLSchema } from 'graphql';
import { addApolloLogging } from 'apollo-logger';

import { makeExecutableSchema, addMockFunctionsToSchema, addErrorLoggingToSchema } from 'graphql-tools';
import { resolvers, typeDefs } from '@sample-stack/graphql-schema';
import { GraphQLAnyObject } from './scalar';
const rootSchemaDef = require('./root-schema.graphqls');
// import rootSchemaDef from './root_schema.graphqls';
import { logger } from '@sample-stack/utils';
import { pubsub } from '../container';

const DefaultResolver = {
  AnyObject: GraphQLAnyObject,
};

const schema: GraphQLSchema = makeExecutableSchema({
  resolvers: resolvers(pubsub, logger),
  typeDefs: [rootSchemaDef].concat(typeDefs) as Array<any>,
});

addErrorLoggingToSchema(schema, { log: (e) => logger.error(e) });

addMockFunctionsToSchema({
  mocks: {},
  preserveResolvers: true,
  schema,
});


export { schema };
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:30,代码来源:schema.ts


示例6: makeExecutableSchema

import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools'
import { graphql, ExecutionResult } from 'graphql'
import * as fs from 'fs-extra'

const typeDefs = fs.readFileSync(__dirname + '/cluster.graphql', 'utf-8')

const schema = makeExecutableSchema({ typeDefs })

addMockFunctionsToSchema({
  schema,
  mocks: {
    Migration: () => ({
      revision: 5,
    }),
  },
})

export const MockGraphQLClient = () => {
  return {
    request(query, variables) {
      return graphql(schema, query, {}, {}, variables) as any
    },
  }
}

export { ExecutionResult }
开发者ID:ahmb84,项目名称:prisma,代码行数:26,代码来源:mock-client.ts


示例7: makeExecutableSchema

// other option: https://github.com/MadRabbit/graphql-mock
import { SchemaLink } from 'apollo-link-schema';
import { addMockFunctionsToSchema, makeExecutableSchema } from 'graphql-tools';
import { typeDefs } from '../../server/schemas';

const schema = makeExecutableSchema({ typeDefs });
const mocks = {
  Query: () => ({
    books: () => [{ title: 'Book1 ', author: 'Tomas' }, { title: 'Book 2', author: 'Valeria' }]
  })
};
addMockFunctionsToSchema({ mocks, schema });
export const schemaLink = new SchemaLink({ schema });
开发者ID:tomitrescak,项目名称:babel-ts,代码行数:13,代码来源:mocks.ts


示例8: makeExecutableSchema

import { ApolloLink, Observable } from "apollo-link";

import { graphql, graphqlSync, print, introspectionQuery, IntrospectionQuery } from "graphql";
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import gql from "graphql-tag";

import { SubscriptionCovertLink, EntityInfo } from "../lib/";

import fs from "fs";
import path from "path";
import { CommentAdded } from "./graphql/CommentAdded";

const schemaString = fs.readFileSync(path.resolve(__dirname, "./schema.graphql"), { encoding: "utf8" });

const schema = makeExecutableSchema({ typeDefs: schemaString });
addMockFunctionsToSchema({ schema });
const introspectionResult = graphqlSync(schema, introspectionQuery).data! as any as IntrospectionQuery;

function delay(ms: number) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
    }, ms);
  });
}

export const link = new ApolloLink(operation => {
  return new Observable(observer => {
    const { query, operationName, variables } = operation;

    (async () => {
开发者ID:vvakame,项目名称:til,代码行数:31,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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