當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。