当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript apollo-fetch.createApolloFetch函数代码示例

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


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

示例1: it

        it('returns thrown context error as a valid graphql result', async () => {
          const nodeEnv = process.env.NODE_ENV;
          delete process.env.NODE_ENV;
          const typeDefs = gql`
            type Query {
              hello: String
            }
          `;
          const resolvers = {
            Query: {
              hello: () => {
                throw Error('never get here');
              },
            },
          };
          server = new ApolloServer({
            typeDefs,
            resolvers,
            context: () => {
              throw new AuthenticationError('valid result');
            },
          });

          app = new Server({ port });

          await server.applyMiddleware({
            app,
            disableHealthCheck: true,
          });
          await app.start();

          httpServer = app.listener;
          const uri = app.info.uri + '/graphql';

          const apolloFetch = createApolloFetch({ uri });

          const result = await apolloFetch({ query: '{hello}' });
          expect(result.errors.length).toEqual(1);
          expect(result.data).toBeUndefined();

          const e = result.errors[0];
          expect(e.message).toMatch('valid result');
          expect(e.extensions).toBeDefined();
          expect(e.extensions.code).toEqual('UNAUTHENTICATED');
          expect(e.extensions.exception.stacktrace).toBeDefined();

          process.env.NODE_ENV = nodeEnv;
        });
开发者ID:apollostack,项目名称:apollo-server,代码行数:48,代码来源:ApolloServer.test.ts

示例2: Promise

    return new Promise((resolve, reject) => {
      const fetch = createApolloFetch({
        uri: url
      });

      fetch({
        query: '{ hello }',
      }).then(res => {
        if ( res.data === undefined ) {
          reject('Failed to call hello');
        }
        resolve(res.data.hello);
      }).catch( err => {
        reject(err);
      });
    });
开发者ID:toannvbk93,项目名称:goemon,代码行数:16,代码来源:hello-service.ts

示例3: it

      it('applies tracing extension with cache control enabled', async () => {
        const { url: uri } = await createServer({
          typeDefs,
          resolvers,
          tracing: true,
          cacheControl: true,
        });

        const apolloFetch = createApolloFetch({ uri });
        const result = await apolloFetch({
          query: `{ books { title author } }`,
        });
        expect(result.data).toEqual({ books });
        expect(result.extensions).toBeDefined();
        expect(result.extensions.tracing).toBeDefined();
      });
开发者ID:apollostack,项目名称:apollo-server,代码行数:16,代码来源:ApolloServer.test.ts

示例4: it

    it('configures cors', async () => {
      server = new ApolloServer({
        typeDefs,
        resolvers,
      });

      const { url: uri } = await server.listen();

      const apolloFetch = createApolloFetch({ uri }).useAfter(
        (response, next) => {
          expect(
            response.response.headers.get('access-control-allow-origin'),
          ).toEqual('*');
          next();
        },
      );
      await apolloFetch({ query: '{hello}' });
    });
开发者ID:simonjoom,项目名称:react-native-project,代码行数:18,代码来源:index.test.ts


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