本文整理汇总了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;
}
示例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;
}
示例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);
});
示例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();
});