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