本文整理匯總了TypeScript中graphql.print函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript print函數的具體用法?TypeScript print怎麽用?TypeScript print使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了print函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should be able to alias a document containing a query and a named fragment', () => {
const doc = gql`
query authorStuff {
author {
...authorDetails
}
}
fragment authorDetails on Author {
firstName
lastName
}`;
const exp = gql`
query authorStuff {
___authorStuff___requestIndex_2___fieldIndex_0: author {
...___authorStuff___requestIndex_2___authorDetails
}
}
fragment ___authorStuff___requestIndex_2___authorDetails on Author {
___authorStuff___requestIndex_2___fieldIndex_1: firstName
___authorStuff___requestIndex_2___fieldIndex_2: lastName
}
`;
const aliasName = getOperationDefinitionName(getQueryDefinition(doc), 2);
const aliasedDoc = applyAliasNameToDocument(doc, aliasName);
assert.equal(print(aliasedDoc), print(exp));
});
示例2: it
it('should also remove variables when removing empty selection sets', async () => {
const query = parse(`
query customerQuery($id: ID!, $limit: Int) {
customerById(id: $id) {
id
name
bookings(limit: $limit) {
paid
}
}
}
`);
const filteredQuery = filter.transformRequest({
document: query,
variables: {
id: 'c1',
limit: 10
}
});
const expected = parse(`
query customerQuery($id: ID!) {
customerById(id: $id) {
id
name
}
}
`);
expect(print(filteredQuery.document)).to.equal(print(expected));
});
示例3: test
test("simple case", () => {
const operation = createOperation({}, {
query: gql`
subscription Foo {
commentAdded {
id
text
}
}
`,
});
operation.operationName = "Foo";
const result = subscriptionToQuery(introspectionResult, operation);
expect(result).toBeDefined();
const query = result!["commentAdded"];
expect(query).toBeDefined();
const expected = gql`
query Resolve_Foo_commentAdded ($id: ID!) {
commentAdded: node(id: $id) {
... on Comment {
id
text
}
}
}
`;
delete (query as any).loc;
delete expected.loc;
expect(print(query)).toEqual(print(expected));
expect(query).toEqual(expected);
});