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


TypeScript parser.parse函数代码示例

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


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

示例1: parseDocument

function parseDocument(doc: string): Document {
  const parsed = parse(doc);

  if (!parsed || parsed.kind !== 'Document') {
    throw new Error('Not a valid GraphQL document.');
  }

  return parsed as Document;
}
开发者ID:ignitedsgn,项目名称:apollo-client,代码行数:9,代码来源:gql.ts

示例2: parseDocument

function parseDocument(doc: string): Document {
  if (cache[doc]) {
    return cache[doc];
  }

  const parsed = parse(doc);

  if (!parsed || parsed.kind !== 'Document') {
    throw new Error('Not a valid GraphQL document.');
  }

  cache[doc] = parsed;

  return parsed as Document;
}
开发者ID:AgtLucas,项目名称:apollo-client,代码行数:15,代码来源:gql.ts

示例3: test

        test('happy-case-query', async () => {
            const spyonAuth = jest.spyOn(Auth, 'currentCredentials').mockImplementationOnce(() => {
                return new Promise((res, rej) => {
                    res('cred');
                });
            });

            const spyon = jest.spyOn(RestClient.prototype, 'post')
                .mockImplementationOnce((url, init) => {
                    return new Promise((res, rej) => {
                        res({})
                    });
                });

            const api = new API(config);
            const url = 'https://appsync.amazonaws.com',
                region = 'us-east-2',
                apiKey = 'secret_api_key',
                variables = { id: '809392da-ec91-4ef0-b219-5238a8f942b2' };
            api.configure({
                aws_appsync_graphqlEndpoint: url,
                aws_appsync_region: region,
                aws_appsync_authenticationType: 'API_KEY',
                aws_appsync_apiKey: apiKey
            })
            const GetEvent = `query GetEvent($id: ID! $nextToken: String) {
                getEvent(id: $id) {
                    id
                    name
                    where
                    when
                    description
                    comments(nextToken: $nextToken) {
                      items {
                        commentId
                        content
                        createdAt
                      }
                    }
                  }
                }`;

            const doc = parse(GetEvent);
            const query = print(doc);

            const headers = {
                Authorization: null,
                'X-Api-Key': apiKey
            };

            const body = {
                query,
                variables,
            };

            const init = {
                headers,
                body,
                signerServiceInfo: {
                    service: 'appsync',
                    region,
                }
            };

            await api.graphql(graphqlOperation(GetEvent, variables));

            expect(spyon).toBeCalledWith(url, init);
        });
开发者ID:lukethompson,项目名称:aws-amplify,代码行数:68,代码来源:API-test.ts

示例4: Promise

        test.skip('happy-case-subscription', (done) => {
            const spyonAuth = jest.spyOn(Auth, 'currentCredentials').mockImplementation(() => {
                return new Promise((res, rej) => {
                    res('cred');
                });
            });
            
            // TODO: This mock doesnt work on jest
            const spyon = jest.spyOn(RestClient.prototype, 'post')
                .mockImplementation((url, init) => {
                    return new Promise((res, rej) => {
                        res({})
                    });
                });

            const api = new API(config);
            const url = 'https://appsync.amazonaws.com',
                region = 'us-east-2',
                apiKey = 'secret_api_key',
                variables = { id: '809392da-ec91-4ef0-b219-5238a8f942b2' };

            api.configure({
                aws_appsync_graphqlEndpoint: url,
                aws_appsync_region: region,
                aws_appsync_authenticationType: 'API_KEY',
                aws_appsync_apiKey: apiKey
            });
            const pubsub = new PubSub(config);

            const SubscribeToEventComments = `subscription SubscribeToEventComments($eventId: String!) {
                subscribeToEventComments(eventId: $eventId) {
                  eventId
                  commentId
                  content
                }
              }`;

            const doc = parse(SubscribeToEventComments);
            const query = print(doc);

            const headers = {
                Authorization: null,
                'X-Api-Key': apiKey
            };

            const body = {
                query,
                variables,
            };

            const init = {
                headers,
                body,
                signerServiceInfo: {
                    service: 'appsync',
                    region,
                }
            };

            const observable = api.graphql(graphqlOperation(SubscribeToEventComments, variables)).subscribe({
                next: () => {
                    done();
                }
            });

            pubsub.publish('topic1', 'my message');

            expect(observable).not.toBe(undefined);
            expect(spyon).toBeCalled();
        });
开发者ID:lukethompson,项目名称:aws-amplify,代码行数:70,代码来源:API-test.ts


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