Skip to content

Commit 30c4948

Browse files
committed
Add getDescription.js
1 parent f898798 commit 30c4948

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
3+
import { parse } from 'graphql/language';
4+
import getDescription from '../getDescription';
5+
6+
describe('getDescription()', () => {
7+
const generateNode = description => parse(`
8+
# ${description === undefined ? '' : description}
9+
type Type {
10+
int: Int
11+
}
12+
`).definitions[0];
13+
14+
test('gets description', () => {
15+
const description = 'A description.';
16+
expect(getDescription(generateNode(description))).toBe(description);
17+
});
18+
19+
test('returns undefined if there\'s no description', () => {
20+
expect(getDescription(generateNode())).toBeUndefined();
21+
});
22+
23+
test('return undefined if there\'s an empty description', () => {
24+
expect(getDescription(generateNode(' '))).toBeUndefined();
25+
});
26+
});

src/build/getDescription.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* @flow */
2+
3+
import type { Location } from 'graphql/language';
4+
import { getDescription } from 'graphql/utilities/buildASTSchema';
5+
6+
export default (node: { loc?: Location }) => getDescription(node) || undefined;

0 commit comments

Comments
 (0)