本文整理匯總了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();
});