Skip to content

Commit 5275c9a

Browse files
committed
Add getDescription.js
1 parent 06611a7 commit 5275c9a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 26 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* @flow */
2+
3+
import type { Location } from 'graphql/language';
4+
import { getDescription as get } from 'graphql/utilities/buildASTSchema';
5+
6+
export default function getDescription(node: { loc?: Location }) {
7+
return get(node) || undefined;
8+
}

0 commit comments

Comments
 (0)