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